【发布时间】:2023-02-14 00:29:28
【问题描述】:
我在 Python 3.9 中有以下代码:
first_entries = [r[0] for r in result]
seconds_entries = [r[1] for r in result]
third_entries = [r[2] for r in result]
其中 result 是以下形式的元组列表:
result = [(x1,x2,x3),(y1,y2,y3),...]
有没有办法将其写入一行并仅对结果进行一次迭代?
【问题讨论】:
-
也许
first_entries, seconds_entries, third_entries = zip(*result),但我还没有测试过