filter2
holger krekel
pyth at devel.trillke.net
Thu Jun 13 12:27:51 EDT 2002
Jeff Epler wrote:
> If you're benchmarking, try a solution like this in the mix. It only
> has one map/filter call, not map+2*filter. (uses nested scopes and the
> new bool() builtin, but this can be avoided if necessary)
>
> def filter2(test, list):
> l1 = []
> l2 = []
> funcs = [l2.append, l1.append]
> map(lambda x: funcs[bool(test(x))](x), list)
> return l1, l2
nice!
holger
More information about the Python-list
mailing list