0

How would you go about overlapping lists, without the boring and time consuming for-loops?

Functionality:

l1=[1,2,3]
l2=['a','b','c']
overlap(l1,l2) #[(1,'a'),(2,'b'),(3,'c')]
overlap(l2,l1) #[('a',1),('b',2),('c',3)]
Anshu Dwibhashi
  • 4,617
  • 3
  • 28
  • 59

1 Answers1

7

Use the built-in zip function:

>>> zip(l1,l2)
[(1,'a'),(2,'b'),(3,'c')]

>>> zip(l2,l1)
[('a', 1), ('b', 2), ('c', 3)]
K DawG
  • 13,287
  • 9
  • 35
  • 66