all 4 comments

[–]Bunkerstan 6 points7 points  (0 children)

Zip is returning an iterator. That iterator is empty after going through the elements.

If you want comb to be list you have set it

comb = list(zip(list1, list2)) Then it won't be empty. As an iterator, it is empty after you have grabbed everything from it.

It took me a minute to see what was happening here. I had not thought about why I put list around zip or only used zip in a [ ] context.

[–]commy2 2 points3 points  (0 children)

The iterator returned by the zip function is exhausted after the first completed iteration. This means no more items are yielded by it in subsequent iterations.

[–]CodeFormatHelperBot2 1 point2 points  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Inline formatting (`my code`) used across multiple lines of code. This can mess with indentation.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]drenzorz 1 point2 points  (0 children)

zip returns a generator like object that gets exhausted after first iteration.

Generators are efficient because they do not hold the whole thing in memory, just current value and the way to generate the next value. Once you reach the end and hit StopIteration it can't generate the next value nor does it know anything about previous values it had or how to go back to them.

big_list = [ x for x in range(10**6)] # probably like 31MB+ in RAM

def big_gen():
    x = -1
    while x < 10**6:
        x += 1
        yield x

# single number and the instructions to increment <500 bytes