-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Itertools recipes improvements #116842
Comments
Yes to the roundrobin test update. No to changing unique_everseen. In general, I update the loop invariant first. This helps me avoid bugs. Also, changing the order doesn't change the total amount of work. It just shifts work from when the first element is emitted to when the iterator stops. Yes to changing the subsequence terminology in the comment. It is really pedantic but we might as well change it to "continuous subsequence". The word "substring" isn't quite right because it also applies to bytes and the user defined types that implement continuous subsequence searches. I'll make the edits a bit later when I get home. Thanks for looking over the code. Nice to know that someone besides me reads it. |
Should the
Depends. If the user for example only requests the first three (like
"contiguous" seems more popular, 18.400 results vs 4.930.
The comment only talks about "bytes and str". And
I love itertools and have been reading/checking all changes for a long time :-). Btw do you get notified about comments on merged commits? I made one once and don't know whether you saw it (you did do the change a while later). |
) (cherry picked from commit 41e844a) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Okay. Fixed. |
@pochmann3 You may interested in the issues I recently filed in the more-itertools docs. Minor implementation tweaks have more of a payoff there because people run that code instead of just reading it. |
roundrobin
cpython/Doc/library/itertools.rst
Lines 1570 to 1571 in 5f52d20
That looks weird. Round-robin with a single iterable? And the ranges aren't iterated? I suspect this was intended:
unique_everseen
These could be lazier by yielding first (before updating
seen
):cpython/Doc/library/itertools.rst
Lines 894 to 895 in 7bbb9b5
cpython/Doc/library/itertools.rst
Lines 900 to 901 in 7bbb9b5
The similar "roughly equivalent" code of
cycle
and thefactor
recipe also yield as early as they can.iter_index
cpython/Doc/library/itertools.rst
Line 1420 in 7bbb9b5
Not really subsequence searches but substring searches. For example, "fbr" is a subsequence of "foobar", but they don't search for that. See Subsequence and Substring at Wikipedia.
@rhettinger
Linked PRs
The text was updated successfully, but these errors were encountered: