![](/img/trans.png)
[英]how to transform a list of list of tuples into an np array where each element is a tuple in python
[英]How to transform list of tuples into a tuple?
我该如何转型
[(212, u'comment', 0L), (205, u'main', 0L)]
入这个?
(0L, 0L)
>>> 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.