[issue38200] Adding itertools.pairwise to the standard library?

2020-11-30 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2020-11-30 Thread Raymond Hettinger


Raymond Hettinger  added the comment:


New changeset cc061d0e6fb2569efa91531686f75b89e94ec865 by Raymond Hettinger in 
branch 'master':
bpo-38200: Add itertools.pairwise() (GH-23549)
https://github.com/python/cpython/commit/cc061d0e6fb2569efa91531686f75b89e94ec865


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2020-11-28 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
keywords: +patch
pull_requests: +22429
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/23549

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2020-11-28 Thread Raymond Hettinger


Change by Raymond Hettinger :


Added file: https://bugs.python.org/file49633/pairwise.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-11-30 Thread bbayles


Change by bbayles :


--
nosy: +bbayles

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-10-01 Thread Matteo Dell'Amico


Matteo Dell'Amico  added the comment:

Sorry for taking so long to answer, I didn't see notifications somehow.

Raymond, my use case is in general something that happens when I'm doing 
analytics on sequences of events (e.g., URLs visited by a browser) or paths in 
a graph. I look at pairs and do something based on the pair of events (e.g., 
did the user likely clicked an advertising link? did they go to a potentially 
risky webpage, possibly by clicking a link?)

I see the argument for generalizing to a sliding window, although that may lead 
people to choosing inefficient algorithms for sliding average or median.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-09-18 Thread Tim Peters


Tim Peters  added the comment:

There's an eternal culture clash here:  functional languages have a long 
history of building in just about everything of plausible use, regardless of 
how trivial to build on other stuff.  This started when LISP was barely 
released before (cadr x) was introduced as a shorthand for (car (cdr x)), and 
(caddr x) for (car (cdr (cdr x))), and so on.  Which more modern functional 
languages also supply (second x) and (third x) spellings for (_and_ nth(2, x) 
and nth(3, x) spellings).

This one is harder to get right than those, but not hard at all.  But it's not 
coincidence that itertoolz[1] (note the trailing 'z') also supplies it, spelled 
`sliding_window(width, iterable)` there.  Working with finite difference 
algorithms is probably "the most obvious" use case for a width of 2.

More esoterically, one of my favorite "technical indicators" for stock analysis 
is a dead simple 20-period simple moving average, which can be built very 
conveniently (although not very efficiently - but I don't usually care) by 
mapping a mean function over a sliding window of width 20.

BTW, if you want padding on each end, you can apply pairwise to `chain([first], 
iterable, [last])`.

A related function is breaking an iterable into _non_-overlapping chunks of a 
given width.  itertoolz spells that "partition".  For me that comes up more 
often than overlapping windows.

I like having these things around, but it's not a big deal.  Perhaps it would 
be an easier decision in Python if we gave up on believing that everything in 
itertools _must_ be coded in C.  In functional idioms sometimes speed isn't the 
point at all, but rather using conventional names for simple but compound 
functionality.  Like that "sliding window" is a concept in its own right.  If 
I'm _picturing_ an algorithm in terms of a sliding window, then - of course - 
the shortest distance to working code is to use a facility that already 
implements that concept.

Which is a long way of saying +0.

[1] https://toolz.readthedocs.io/en/latest/api.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-09-18 Thread Vedran Čačić

Vedran Čačić  added the comment:

I also use it all the time. Most recently in some numerical calculation for 
successive differences. My main problem is that I'm too often tempted to just 
zip l with l[1:], thereby restricting the code to sequences, when it would work 
perfectly well for any iterable. (Just as I sometimes write range(lots of 
nines) instead of itertools.count() *shame*;)

--
nosy: +veky

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-09-17 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

FWIW, pairwise() is in the more-itertools module.  A quick code search does 
show occasional use in the wild:  
https://github.com/search?q=language%3Apython+more_itertools.pairwise=Code 
 

In my own code, I've had some cases that almost fit but they needed custom 
padding on one end or both ends:  zip([0.0] + data, data + [1.0]). Also, its 
unclear where anyone would want a wider sliding window.

Tim, do you have any thoughts about pairwise()?

--
nosy: +tim.peters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-09-17 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Can you show some examples of what you used it for?

--
assignee:  -> rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-09-17 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +rhettinger
type:  -> enhancement
versions: +Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38200] Adding itertools.pairwise to the standard library?

2019-09-17 Thread Matteo Dell'Amico


New submission from Matteo Dell'Amico :

I use itertools.pairwise all the time and I wonder if the same happens to 
others. I'm thinking that others may be in the same situation, and having this 
simple recipe already included in the library would be definitely more 
convenient than copy/pasting the recipe. Also, it may improve its visibility...

--
components: Library (Lib)
messages: 352642
nosy: della
priority: normal
severity: normal
status: open
title: Adding itertools.pairwise to the standard library?

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com