Skip to content

Conversation

@rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Nov 29, 2020

This is a first draft. Needs more thought on refcnts. Needs docs, tests, and a better doctstring.

https://bugs.python.org/issue38200

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code LGTM. Needed documentation, tests, and implementation of __reduce__.

@rhettinger
Copy link
Contributor Author

I'm intending to leave out __reduce__:

  • We haven't promised in the docs that all itertools are pickable.
  • Experience with the more-itertools package suggests that it isn't needed.
  • Experience with the regular itertools module suggests unnecessarily adding pickle support gets in the way of maintenance and is itself a recurring source of bugs.
  • Also, I never liked the way this was done for the other itertools where it replays the prior execution history.
@rhettinger rhettinger changed the title bpo-38200: Add itertools.pairwise [WIP] bpo-38200: Add itertools.pairwise() Nov 30, 2020
@pylang
Copy link

pylang commented Jan 23, 2021

Greetings. It's exciting to see new tools added to the Standard Library.

Since pairwise is already a recipe, I'm wondering whether if this is worth generalizing to a sliding-window tool instead, e.g. window? I saw some rationale in the original bug post, but in cases where a pairwise operation is needed, I usually implement a quick list(zip(lst, lst[1:])) recipe instead.

If a more general tool is needed (e.g. one that applies to iterators), then I think it's worth generalizing the window size as well. I understand the topic of sliding-windows has been discussed in the past, but that was prior to officially adopting a windowing tool like pairwise into itertools. Since then I've seen many sliding-window problems on StackOverflow and in more-itertools. I can give more links on specific use cases if requested.

Many thanks.

adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
@merwok
Copy link
Member

merwok commented Dec 1, 2021

Hi @pylang — python-dev does not use pull requests for design discussions, only code reviews.
For open tickets, the bug tracker is the right place to discuss design, now that this one is closed, better go to the python-dev mailing list or the https://discuss.python.org/ forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants