Python namedtuple T._make(iterable) vs T(* iterable)
namedtuple, python
Solution
It may be useful to have a function that does the same as `T(*iterable)`. Consider this:
a = namedtuple('a', 'x, y')
b = [(x, x) for x in xrange(10)]
map(a._make, b)
Sure, you could also do:
[a(*x) for x in b]
but this correspondence to functions happens in other places, like the `operator` module. This is just speculation though, I don't know if that is the rationale for `_make`.
EDIT: I found some more information on this; following a link in a previous Stack Overflow question, regarding the reason for the underscore in namedtuple methods, I read a page that states:
The inspiration for the _make() classmethod came from Robin Becker and Giovanni Bajo who pointed-out an important class of use cases where existing sequences need to be cast to named tuples.
Problem
Minor question: I don't understand why Python's namedtuple types have a _make() function. As far as I can tell, if T is a type created with namedtuple, then ``` T._make(iterable) and T(* iterable) ``` are the same thing. So why have a _make() function? Is there something I'm missing?