【发布时间】:2015-05-15 04:51:15
【问题描述】:
如果我有
nums_and_words = [(1, 'one'), (2, 'two'), (3, 'three')]
并且愿意
nums = [1, 2, 3]
words= ['one', 'two', 'three']
我将如何以 Python 的方式做到这一点?我花了一分钟才意识到为什么以下不起作用
nums, words = [(el[0], el[1]) for el in nums_and_words]
我很好奇是否有人可以提供类似的方式来实现我正在寻找的结果。
【问题讨论】:
标签: python list-comprehension iterable-unpacking