我有这个列表[(1,),(2,),(3,),(4,)]
如何将其转换为1d数组[1,2,3,4]
?
答案 0 :(得分:3)
您可以解压缩所有元组:
>>> [e for e, in [(1,),(2,),(3,),(4,)]]
[1, 2, 3, 4]
答案 1 :(得分:1)
test = [(1,),(2,),(3,),(4,)]
single = []
for i in test:
single.append(i[0])
print(single)
输出
[1, 2, 3, 4]
答案 2 :(得分:0)
i = [(1,),(2,),(3,),(4,)]
print([tup for tups in i for tup in tups])
输出 -
[1, 2, 3, 4]