所以,我有x=[(12,), (1,), (3,)] (元组列表),我想要以最好的方式使用x=[12, 1, 3] (整数列表)?你能帮帮忙吗?
发布于 2013-02-27 02:01:47
y = [i[0] for i in x]但是,这只适用于每个元组中的一个元素。
但是,如果每个元组有多个元素,则可以使用稍微复杂一点的列表理解:
y = [i[j] for i in x for j in range(len(i))]参考:List Comprehensions
https://stackoverflow.com/questions/15096021
复制相似问题