list to map?

Alex alex at somewhere.round.here
Tue May 18 23:30:39 EDT 1999


>From the followups to followups I've seen (I always receive people's
posts out of order), it looks like someone might already have said this.
But in case not, you could use the operator module:

>>> import operator
>>> x = [(1,2),(3,4),(5,6)]
>>> x_0 = map (operator.getitem, x, len (x) * [0])
>>> x_1 = map (operator.getitem, x, len (x) * [1])
>>> x_dictionary = {}
>>> map (operator.setitem, len (x) * [x_dictionary], x_0, x_1)
[None, None, None]
>>> print x_dictionary
{3: 4, 1: 2, 5: 6}
>>> 

It's a monstrosity, but at least it hasn't stripped yet. :)

Alex.




More information about the Python-list mailing list