-1

Hello I have this list :

a = [["Hello", "Good Bye"],["Country", "Test"]]

And I would like to concatenate the sub items I mean I would like to have this :

a = ["Hello Good Bye", "Country Test"]

Could you help me please ?

Thank you very much !

John Fichter
  • 1
  • 1
  • 3

2 Answers2

3

You can use a list comprehension:

[' '.join(sublist) for sublist in a]
Carsten
  • 2,765
  • 1
  • 13
  • 28
2

You can use map, it applies a function to all elements in a list.

>>> a = [["Hello", "Good Bye"],["Country", "Test"]]
>>> res = list(map(" ".join, a))
>>> res
['Hello Good Bye', 'Country Test']
palvarez
  • 1,508
  • 2
  • 8
  • 18