Supplementing the std lib (Was: partial sums problem)

Paul Rubin no.email at nospam.invalid
Wed Sep 29 21:06:26 EDT 2010


kj <no.email at please.post> writes:
> But in the immediate term, cusum is not part of the standard library.
>
> Where would you put it if you wanted to reuse it?  Do you create
> a module just for it?  Or do you create a general stdlib2 module
> with all those workhorse functions that have not made it to the
> standard library?  Or something else entirely?

In a typical application you'd have a bunch of such utility functions in
a single "utils.py" module or something like that.  Java programs use
separate files for each class, so you get zillions of files, but Python
users tend to put more code in each file. 

As for the stdlib, the natural places for such a function would be
either itertools or functools, and the function should probably be called
"scan", inspired by this:

  http://en.wikibooks.org/wiki/Haskell/List_processing#Scans

Python's version would be like "scanl" with an optional arg to make it
like "scanl1".



More information about the Python-list mailing list