• Python question of the day

    What would be the output of executing the following code:
    y = zip(*[iter(range(7))]*3)
    print(list(y))
     [(0, 3, 6, 9, 12, 15, 18)]
     [(0, 1), (2, 3), (3, 4)]
     [(0, 1, 2), (3, 4, 5)]
     IndexError
    Explanation:
    iter( ) is an iterator over a sequence. [iter(x)] * 3 produces a list with three listiterator objects: each list iterator is an iterator of x. the * that is passed to the zip( ) function before anything else unpacks the sequence into arguments so that you’re passing the same iterator three times to the zip( ) function, and it pulls an item from the iterator each time.


    Top 100 python interview questions:


  • python bootcamp 2021
datai analytics