【发布时间】:2014-07-18 17:36:52
【问题描述】:
我有 2 个列表:
x = ['a','b','c']
y = ['d','e','f']
我需要一个列表:
z = [['a','d'],['b','e'],['c','f']]
我尝试了什么:
# Concatenate x and y with a space
w = []
for i in range(len(x)):
w.append(x[i]+" "+y[i])
# Split each concatenated element into a sublist
z = []
for i in range(len(w)):
z.append(w[i].split())
有没有办法在不使用 2 个 for 循环的情况下直接执行此操作? (我对 Python 很陌生)
【问题讨论】:
标签: python python-2.7