map, filter, reduce, zip, range, and.. slice?
eyal at hyperroll.com
Wed Oct 31 00:40:13 CET 2001
Hey. Recently, I've been heavily using functional-style programming in
Python, doing almost all of my text processing and so with complex nested
lambda clauses. I love those, as they are so short, and seem to work with
a painless "debug" cycle, usually consisting of some missing reduce initial
value or so.
To get to the point, I've almost always lacked a 'slice' function, that
slices sequences into smaller chunks. For example:
divide("Hello world!", 2) => ["He", "ll", "o ", "wo", "rl", "d!"]
This can be useful to map() items or chunks inside sequences, rather than
individual items. It can also be useful for for'ing through chunks of
sequences. I ended up re-coding this function everywhere I've got Python
installed (which is a lot of places, that are not necessarily networked :).
I was wondering:
A) Is there an already existing way to do this in the standard library, via
a function that does this exactly, or some similar functionality?
B) If not, will it be a good idea to incorporate such a function into the
More information about the Python-list