-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
  • 112,593
  • 23
  • 157
  • 280

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
  • 81,317
  • 8
  • 19
  • 49