-2

I'm trying to combine 2 Lists of strings in Python:

list_1 = [A, C, E]
list_2 = [B, D, F]

And this would be the desired output

mergedList = [A, B, C, D, E, F]

I've tried to use the itertools module but I haven't had success.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

Using zip and itertools.chain:

list_1 = ['A', 'C', 'E']
list_2 = ['B', 'D', 'F']

from itertools import chain

mergedList = list(chain.from_iterable(zip(list_1, list_2)))

Output: ['A', 'B', 'C', 'D', 'E', 'F']

mozway
  • 194,879
  • 13
  • 39
  • 75