开发者

Pass each element of a list to a function that takes multiple arguments in Python?

开发者 https://www.devze.com 2023-01-13 10:04 出处:网络
For example, if I have a=[[\'a\',\'b\',\'c\'],[1,2,3],[\'d\',\'e\',\'f\'],[4,5,6]] How can I get each element 开发者_StackOverflow社区of a to be an argument of say, zip without having to type

For example, if I have

a=[['a','b','c'],[1,2,3],['d','e','f'],[4,5,6]]

How can I get each element 开发者_StackOverflow社区of a to be an argument of say, zip without having to type

zip(a[0],a[1],a[2],a[3])?


Using sequence unpacking (thanks to delnan for the name):

zip(*a)


Chain()?

http://docs.python.org/library/itertools.html#itertools.chain

nm, read it wrong. That won't work.

0

精彩评论

暂无评论...
验证码 换一张
取 消