> >> seq = [1,2,3,4,5] > >> if any(seq, lambda x: x==5): > >> ... > >> > >> which is clearly more readable than > >> > >> reduce(seq, lambda x,y: x or y==5, False) > > > > How about this? > > > > if any(x==5 for x in seq): > > Aren't all of these equivalent to: > > if 5 in seq: > ... Yeah, but you can't do more complicated expressions that way, like any(lambda x: x[3] == "thiskey") I think it makes a lot of sense for any and all to take optional predicate function arguments. But perhaps the syntax should be: X in SEQ If X is a predicate function, it gets called to determine "equals"; if an expression or other object, the normal rules apply. Of course, then you couldn't look for a function in a set of functions... I suppose (len([x for x in SEQ if PRED(x)]) > 0) will suffice for now. Obvious enough, Martin? Bill
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4