Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Careless zips of iterators #121

Closed
pmjpawelec opened this issue May 13, 2019 · 1 comment
Closed

Careless zips of iterators #121

pmjpawelec opened this issue May 13, 2019 · 1 comment

Comments

@pmjpawelec
Copy link

pmjpawelec commented May 13, 2019

Real life lesson. It boggles the mind of many people I show to. Please tell me if this is good enough to add to the wtfpython.

Let's zip some numbers and characters.

>>> a = iter([1,2,3,4,5])
>>> b = ['a', 'b', 'c']
>>> c = ['d', 'e']
>>> print(list(zip(a,b)))
>>> print(list(zip(a,c)))
[(1, 'a'), (2, 'b'), (3, 'c')]
[(5, 'd')]

Somehow the number 4 is lost in the process.

Explanation: The first zip consumes one element (the number 4) from the iterator before realizing it has no matching element from the second list. The element was not "peeked", but taken and it can't be pushed back to a python iterator.

Note: This examples "works" with the reverse order of arguments in the zip.

@satwikkansal
Copy link
Owner

@pmjpawelec Thanks for suggesting this, I'll definitely add it in the next iteration.

satwikkansal added a commit that referenced this issue Jun 9, 2019
satwikkansal added a commit that referenced this issue Oct 28, 2019
muscliary pushed a commit to muscliary/wtfpython that referenced this issue Sep 12, 2023
muscliary pushed a commit to muscliary/wtfpython that referenced this issue Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants