0

You are given two lists of the same length. Using list comprehension, write a Python function to return a merged or combined list of the two lists in the form of a list of tuples. For example, if your two lists are [1, 2, 3] and ["a", "b", "c"], then you should return [(1, "a"), (2, "b"), (3, "c")].

I can't figure out how to index the two lists to put them together

I got multiple errors because I couldn't concatenate two lists together.

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
num
  • 23
  • 5

1 Answers1

4

The zip() function take iterables (can be zero or more), makes iterator that aggregates elements based on the iterables passed, and returns an iterator of tuples.

 [ (a,b) for (a,b) in zip([1,2,3],['a','b','c']) ]
Asnim P Ansari
  • 1,932
  • 1
  • 18
  • 41