07.04.2011 08:37, "A.T.Hofkamp" <[email protected]>: > Try to implement the following list comprehensions with filter (and > map). > > [ x for x in L if x > 3 ] > > [ x + 1 for x in L if x > 3 ] > > [ (x,y) for x in L if x > 3 for y in L if y < x ] > > While I am sure you can write a filter/map/lambda expression that > computes them, I am also sure none of your results is more > readable[1] than the above list comprehensions. > > For bigger list comprehensions, it gets worse. > > > I hope this clarifies a bit why filter is not recommended.
Not really. It explains why `filter()` might not be the choice for
*those* list comprehensions but not why ::
[x for x in xs if predicate(x)]
is any more (un)readable than ::
filter(predicate, xs)
> [1] Readable for the general Python user which typically has not seen
> any functional programming concepts like map and filter.
And has not seen the functional programming concepts like list
comprehensions either. So he has to learn something new anyway.
Maybe there should be warnings about `functools` and `itertools` on the
very same grounds of "unreadable". ;-)
Oh, and quite some people have problems to wrap their heads around OOP…
Ciao,
Marc 'BlackJack' Rintsch
--
Having more money does not insure happiness. People with ten million
dollars are no happier than people with nine million dollars.
-- Hobart Brown
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Python-Projects mailing list [email protected] http://lists.logilab.org/mailman/listinfo/python-projects
