Mai*_*and 1 python list-comprehension list python-3.x python-zip
我正在做一个简单的列表理解:以替代顺序组合两个列表并制作另一个列表。
big_list = [i,j for i,j in zip(['2022-01-01','2022-02-01'],['2022-01-31','2022-02-28'])]
Run Code Online (Sandbox Code Playgroud)
预期输出:
['2022-01-01','2022-01-31','2022-02-01','2022-02-28']
Run Code Online (Sandbox Code Playgroud)
当前输出:
Cell In[35], line 1
[i,j for i,j in zip(['2022-01-01','2022-02-01'],['2022-01-31','2022-02-28'])]
^
SyntaxError: did you forget parentheses around the comprehension target?
Run Code Online (Sandbox Code Playgroud)
进行嵌套理解以将项目从压缩元组中拉出:
big_list = [
i
for t in zip(
['2022-01-01','2022-02-01'],
['2022-01-31','2022-02-28']
)
for i in t
]
Run Code Online (Sandbox Code Playgroud)