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.
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.
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']