组合嵌套列表中的元素 - Python 3

时间:2011-09-25 01:02:27

标签: python list python-3.x

  

可能重复:
  Python3 Concatenating lists within lists

我有

Nested_List = [['John', 'Smith'], ['1', '2', '3', '4']]

我想操纵这个列表,以便得到这个输出:

Nested_List = [['John Smith'], ['1', '2', '3', '4']]

基本上,第一个列表中的两个元素组合在一起。我该怎么做?

1 个答案:

答案 0 :(得分:0)

newElement = [' '.join(NestedList[0])]
Nested_List[0] = newElement

(修改列表,不好的做法,但很简单)