Exercise

The map() function

Let's do some mapping!

Do you remember how zip() works? It merges given Iterables so that items with the same index fall into the same tuple. Moreover, the output is restricted by the shortest Iterable.

Your task is to define your own my_zip() function with *args depicting a variable number of Iterables, e.g. lists, strings, tuples etc. Rather than a zip object, my_zip() should already return a list of tuples.

Comment: args should be checked whether they contain Iterables first. But we omit it for simplicity.

Instructions

100 XP
  • Retrieve Iterable lengths from args using map() and find the minimal length.
  • Within the loop, create the mapping using map() to retrieve the elements in args with the same index i.
  • Convert the mapping to a tuple and append it to the tuple_list.