0

I want to take two lists and merge them together.

list1 = ['1', '2', '3', '4']
list2 = ['one', 'two', 'three', 'four']

Desired output:

[['1', 'one'],['2', 'two'],['3', 'three'],['four', 'four']]

I basically want to combine the elements of both lists in the order they start in their lists. I know the format of the output might seem wonky and is just there for a visual of what i want.

avgnetmin
  • 31
  • 3

2 Answers2

0

You can try this:

list(zip(list1, list2))

output:

[('1', 'one'), ('2', 'two'), ('3', 'three'), ('4', 'four')]
Narendra Prasath
  • 1,501
  • 1
  • 10
  • 20
0

This works

def comblist(list1,list2):
    if len(list1) == 1:
        return [list1 + list2]
    else:
        return [[list1[0]] + [list2[0]]]+ comblist(list1[1:],list2[1:])
Chifrijo
  • 66
  • 7