1

I have two lists:

list1 = [1, 2, 3] 

and

list2 = [a, b, c]

and I want to combine them into 2D list called list3. List three should basically become [[1][a], [2][b],[3][c]. (I think that's how it works though I could be mistaken).

I want to be able to print certain parts of list 3 by using "print(list3[x][y])". Does anyone know how to combine the two lists and define them as list3?

Chanda Korat
  • 2,453
  • 2
  • 19
  • 23

1 Answers1

0

You can try:

>>> list1 = [1, 2, 3]
>>> list2 = ["a", "b", "c"]
>>> list3 = [[[x],[y]] for x,y in zip(list1,list2)]
>>> list3
[[[1], ['a']], [[2], ['b']], [[3], ['c']]]
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61