将列表的每个元素传递给在 Python 中接受多个参数的函数? [英] Pass each element of a list to a function that takes multiple arguments in Python?

查看:26
本文介绍了将列表的每个元素传递给在 Python 中接受多个参数的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有

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

如何让 a 的每个元素成为 zip 的参数而不必输入

How can I get each element of a to be an argument of say, zip without having to type

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

推荐答案

使用序列解包(感谢 delnan 的名字):

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

zip(*a)

这篇关于将列表的每个元素传递给在 Python 中接受多个参数的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆