Zip Function for Cartesian Product

  • Share this:

Code introduction


The function takes an arbitrary number of arguments, each of which is a list, and returns a list containing the Cartesian product of all argument lists.


Technology Stack : List comprehension

Code Type : Generate the Cartesian product of the list

Code Difficulty : Intermediate


                
                    
def zip(*args):
    ziped_list = []
    for i in range(len(args[0])):
        ziped_list.append([args[j][i] for j in range(len(args))])
    return ziped_list