Python Zip Exercises

Let’s check out some exercises that will help understand zip() function better.

Exercise 12-a: Merging 2 Lists with Zip Function

Using zip() function and list() function, create a merged list of tuples from the two lists given.


zip(a, b) can be used to merge two lists together and it returns a list of tuples.

list() function can be used to create lists from iterators that’s created by functions such as range, map, zip, filter…

lst3 = list(zip(lst1, lst2))

Exercise 12-b: Merging a List and a Range with Zip Function

First create a range from 1 to 8. Then using zip, merge the given list and the range together to create a new list of tuples.


range(1,8)  will give you the range you need.

list() function can be used to create lists from iterators that’s created by functions such as range, map, zip, filter…

rng1 = list(range(1,8))
lst = zip(lst1, rng1)