Is tuple unpacking incompatible with `map'?
François Pinard
pinard at IRO.UMontreal.CA
Wed Oct 20 14:32:52 EDT 1999
Hi, friends.
Is it possible that tuple unpacking is not compatible with `map', or is
there something I do not understand properly? Here is a transcript. This is
with Python 1.5.2.
>>> def postsort(pair):
... return pair[1]
...
>>> map(postsort, [(1, 'un'), (2, 'deux'), (3, 'trois')])
['un', 'deux', 'trois']
>>> def postsort(key, item):
... return item
...
>>> map(postsort, [(1, 'un'), (2, 'deux'), (3, 'trois')])
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: not enough arguments; expected 2, got 1
>>>
Maybe `map' is trying to protect me against errors I'm not doing? I would
prefer to use tuple unpacking here, as it allows for cleaner writing.
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list