On Mon, Jun 06, 2022 at 06:17:32PM +0200, Benedict Verhegghe wrote:
> There still is something wrong. I get the second list twice:
>
> odd, even = partition(lambda i: i % 2, range(20))
> print(list(odd))
> [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
> print(list(even))
> [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
Confirmed. But if you replace range(20) with `iter(range(20))`, it
works correctly.
The plot thickens. The duplicated list is not from the second list
created, but the second list *evaluated*. So if you run:
odd, even = partition(...)
as before, but evaluate *even* first and odd second:
print(list(even))
print(list(odd))
it is odd that is doubled, not even.
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/OJIA6HIH6UJYE7X7LU7W46QI2X6UPTK6/
Code of Conduct: http://python.org/psf/codeofconduct/