可以从列表解析中返回两个列表吗? [英] Possible to return two lists from a list comprehension?
本文介绍了可以从列表解析中返回两个列表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从列表理解中返回两个列表?好吧,这显然行不通,但是类似:
Is it possible to return two lists from a list comprehension? Well, this obviously doesn't work, but something like:
rr, tt = [i*10, i*12 for i in xrange(4)]
因此,rr
和tt
都是列表,其结果分别来自i*10
和i*12
.
非常感谢
So rr
and tt
both are lists with the results from i*10
and i*12
respectively.
Many thanks
推荐答案
>>> rr,tt = zip(*[(i*10, i*12) for i in xrange(4)])
>>> rr
(0, 10, 20, 30)
>>> tt
(0, 12, 24, 36)
这篇关于可以从列表解析中返回两个列表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文