[英]is there a way to join list of strings in sublist
I have the following sublist: 我有以下子列表:
[['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
But is it possible to join the list in the sublist? 但是可以将列表加入子列表吗?
[['ab'], ['cd'], ['ef'], ['g']]
>>> L = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
>>> [[''.join(x)] for x in L]
[['ab'], ['cd'], ['ef'], ['g']]
Also, you can use map for it 另外,您可以使用地图
>>> L = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
>>> map(lambda x: [''.join(x)], L)
[['ab'], ['cd'], ['ef'], ['g']]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.