【发布时间】:2022-08-23 20:32:31
【问题描述】:
我有一个元组列表,例如:
bins = [(0, 1500), (0, 1500), (2000, 40000)]
我想在一个循环中将其展平,但每个循环中都没有一个元素。
预期的结果应该是:
[0, 1500, 2000, 40000] # first loop, first element is not there
[0, 1500, 2000, 40000] # second loop, second element is not there
[0, 1500, 0, 1500] # third loop, last element is not there
为了展平它,我可以使用:
from itertools import chain
list(chain.from_iterable(my_iterable))
但我需要找到如何得到这个my_iterable