filter and map / deprecated?
Matt Gerrans
matt.gerrans at hp.com
Wed Dec 17 16:48:41 EST 2003
Also, I suppose if you were *really* in a rush and wanted to get old code
working, then all you'd have to do is add something like this to it:
def map( func, seq ): return [ func(x) for x in seq ]
def filter( func, seq ): return [ x for x in seq if func(x) ]
This will probably be less efficient than Serge's solution. It is probably
also better to have that self-documenting "from legacy ..." in there, to
boot.
I think after a using list comprehensions for a while, they become a lot
more comfortable though, so it is not such a bad thing to develop the habit
of using them instead. Then, in the fullness of time, map() and filter()
will begin to look funny.
More information about the Python-list
mailing list