Reputation: 25554
How can I transform
[(212, u'comment', 0L), (205, u'main', 0L)]
into this?
(0L, 0L)
Upvotes: 0
Views: 95
Reputation: 208435
>>> data = [(212, u'comment', 0L), (205, u'main', 0L)]
>>> tuple(x[2] for x in data)
(0L, 0L)
Or another method...
>>> zip(*data) # just showing what zip(*data) does
[(212, 205), (u'comment', u'main'), (0L, 0L)]
>>> zip(*data)[2]
(0L, 0L)
Using itertools.imap()
and operator.itemgetter()
...
>>> from itertools import imap
>>> from operator import itemgetter
>>> tuple(imap(itemgetter(2), data))
(0L, 0L)
Upvotes: 4