This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients della, rhettinger, tim.peters, veky
Date 2019-09-18.19:15:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568834156.47.0.295989061605.issue38200@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-09-18 19:15:56tim.peterssetrecipients: + tim.peters, rhettinger, della, veky
2019-09-18 19:15:56tim.peterssetmessageid: <1568834156.47.0.295989061605.issue38200@roundup.psfhosted.org>
2019-09-18 19:15:56tim.peterslinkissue38200 messages
2019-09-18 19:15:55tim.peterscreate