# 在列表理解中生成多个项[英] Producing multiple items in a list comprehension

### 问题描述

[ [x,2*x] for x in range(4) ]

....并接收

[ 0,0,1,2,2,4,3,6]

....但是你当然会得到一个列表列表:

[[0, 0], [1, 2], [2, 4], [3, 6]]

list2=[4,5,6] 得到[1,4,2,5,3,6]，"zip"有什么巧妙的方法吗?到

---Joel

## 推荐答案

Joel Koltner 写道:

[ [x,2*x] for x in range(4) ]

...并接收

[ 0,0,1,2,2,4,3,6]

...但你当然会得到一个列表列表:

[[0, 0], [1, 2], [2, 4], [3, 6]]

list2=[4,5,6] 得到[1,4,2,5,3,6]，"zip"有什么巧妙的方法吗?到

---乔尔
--
http://mail.python.org/mailman/listinfo/python-list

def gen(n):

[0, 0, 1, 2, 2, 4, 3, 6]

[ [x,2*x] for x in range(4) ]

...并接收

[ 0,0,1,2,2,4,3,6]

...但你当然会得到一个列表列表:

[[0, 0], [1, 2], [2, 4], [3, 6]]

"列表列表"第一代?
>>[x*y for x in range(4) for y in 1,2]
[0, 0, 1, 2, 2, 4, 3, 6]

list2=[4,5,6] 得到[1,4,2,5,3,6]，有没有"zip"的巧妙方法

>>items = [None] * 6
items[::2] = 1,2,3
items[1::2] = 4,5,6
items
[1、4、2、5、3、6]

[ [x,2*x] for x in range(4) ]

...并接收

[ 0,0,1,2,2,4,3,6]

...但你当然会得到一个列表列表:

[[0, 0], [1, 2], [2, 4], [3, 6]]

list2=[4,5,6] 得到[1,4,2,5,3,6]，"zip"有什么巧妙的方法吗?到

---乔尔
--
http://mail.python.org/mailman/listinfo/python-list

def gen(n):

[0, 0, 1, 2, 2, 4, 3, 6]