Fri Jul 3 13:14:00 EDT 2009
Brad <schickb at gmail.com> writes:
> Maybe this would be difficult to get into the core, but how about this
> idea: Rename the current filter function to something like "split" or
> "partition" (which I agree may be a better name) and modify it to
> return the desired true and false sequences. Then recreate the
> existing "filter" function with a wrapper that throws away the false
This isn't so attractive, since filter takes a sequence input but
returns a list. So if I have an iterator that produces a billion
elements of which I expect three to satisfy some predicate, then
xs = filter(func, seq)
as currently implemented will build a 3-element list and return it.
Under your suggestion, it would also build and throw away an (almost)
billion element list.
More information about the Python-list