0

I have two lists A=[a,b,c,d] B=[1,2,3,4] How can I merge A and B in a nested list of corresponding elements of A and B in Python My outcome will be [[a,1],[b,2],[c,3],[d,4]]. Please help me. TIA

Abra
  • 19,142
  • 7
  • 29
  • 41

1 Answers1

0

Using zip:

A = ['a', 'b', 'c', 'd']
B = [1, 2, 3, 4]

C = [list(x) for x in zip(A,B)]

Result:

[['a', 1], ['b', 2], ['c', 3], ['d', 4]]
Jab
  • 26,853
  • 21
  • 75
  • 114