0

我怎样才能转变

[(212, u'comment', 0L), (205, u'main', 0L)]

进入这个?

(0L, 0L)
4

1 回答 1

4
>>> data = [(212, u'comment', 0L), (205, u'main', 0L)]
>>> tuple(x[2] for x in data)
(0L, 0L)

或者其他方法...

>>> zip(*data)   # just showing what zip(*data) does
[(212, 205), (u'comment', u'main'), (0L, 0L)]
>>> zip(*data)[2]
(0L, 0L)

使用itertools.imap()operator.itemgetter()...

>>> from itertools import imap
>>> from operator import itemgetter
>>> tuple(imap(itemgetter(2), data))
(0L, 0L)
于 2013-02-26T18:06:18.383 回答