[issue46379] itertools.product reference implementation creates temporaries
Markus Wallerberger added the comment: > To a person well versed in recursion and in generator chains it makes sense > but not so much for anyone else. There I pretty much fundamentally disagree. I find the version in the docs much more magical in the sense that it builds up "laterally", i.e., level-by-level, rather than element-by-element. Also, I think from a functional programming perspective, which, let's face it, is what these iteration/generator tools are really modelling, a recursive version is much more natural. It also generalizes nicely to other problems which people may be having -- so it has the added benefit of explaining the code and teaching people useful patterns. Take the itertools.permutation as an example: writing that as it was in the reference implementation the code is IMHO pretty opaque and hard to reason about. Write it in a recursive style and both its working and correctness is immediately obvious. > Plus it is hard to step through by hand to see what it is doing. This I agree with. Anyway, thanks for taking the time to explain the rejection. -- ___ Python tracker <https://bugs.python.org/issue46379> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46379] itertools.product reference implementation creates temporaries
Change by Markus Wallerberger : -- keywords: +patch pull_requests: +28804 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30605 ___ Python tracker <https://bugs.python.org/issue46379> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46379] itertools.product reference implementation creates temporaries
New submission from Markus Wallerberger : The reference implementation of itertools.product creates large temporaries, which we need to remind people of at the top of the code block. However, using generator magic, we don't need to do this and can even simplify the code in the process! Basically,we iterate over a generator of product(*seq[:-1]), and extend each of the values by every value in seq[-1]. -- assignee: docs@python components: Documentation messages: 410573 nosy: docs@python, mwallerb priority: normal severity: normal status: open title: itertools.product reference implementation creates temporaries type: enhancement versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue46379> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com