on-internet
← Community

Creating a function that works like "zip"

Stack Overflow ·

I am trying to make a function that does something similar to "zip". My problem is that the part a = L4[l:len(L4):len(L)] doesn't work. In the case below, it should take every third element from the L4, and append it to a new list, so I ended up with [[1, 4, 7], [2, 5, 8], [3, 6, 9]], but that is not really what is happening. Also, it would be even better if I could make tuples, so it would look like [(1, 4, 7), (2, 5, 8), (3, 6, 9)], but I don't know how to do that... L = [[1,2,3], [4,5,6], [7,8,9]] L4 = [] def my_zip(L): l = 0 for i in L: if isinstance(i, list): my_zip(i) else: L4.append(i)

Comments

Sign in or sign up to comment and upvote.

No comments yet.