[英]Iterating through nested list
How do i create a function to iterate my list in this manner. 我如何创建以这种方式迭代列表的函数。 Seems simply but im stuck...
看起来很简单,但即时通讯卡住了...
myList= [[1,2,3], [4,5,6], [7,8,9]]
def name(myList):
somework..
newList = [[1,4,7]. [ 2,5,8], [3,6,9]]
zip
is what you want + argument unpacking. zip
是您想要的+参数解zip
。 It's awesome. 这很棒。 I like to think of it as python's builtin transpose.
我喜欢将其视为python的内置转置。
newList = zip(*myList)
This will actually give you an iterable (python3.x) or list
(python2.x) of tuple
, but that's good enough for most purposes. 实际上,这将为您提供一个可迭代的(python3.x)或
list
(python2.x)的tuple
,但这对于大多数用途而言已经足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.