我想转换
[(3L, (2L,)), (108L, (11L,))]
到
(3L, (2L,), 108L, (11L,))
我尝试使用此代码执行此操作
["".join(map(str, val)) for val in list]
我的输出变为
('3(2L,)', '108(11L,)')
我如何才能正确转换这个..?
谢谢!
答案 0 :(得分:2)
In [11]: lst = [(3L, (2L,)), (108L, (11L,))]
In [12]: tuple(el for subl in lst for el in subl)
Out[12]: (3L, (2L,), 108L, (11L,))
答案 1 :(得分:1)
另一个选项是来自itertools的chain:
In [1]: from itertools import chain
In [2]: a = [(3L, (2L,)), (108L, (11L,))]
In [3]: tuple(chain(*a))
Out[3]: (3L, (2L,), 108L, (11L,))
答案 2 :(得分:1)
import itertools
L = [(3L, (2L,)), (108L, (11L,))]
tuple(chain.from_iterable(L))