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:
...
?
Cheers,
Brian
Brian Quinlan wrote:
if any(seq, lambda x: x==5):
if any(x==5 for x in seq):
Aren't all of these equivalent to:
if 5 in seq:
...
There should be one-- and preferably only one --obvious way to do it.
Regards,
Martin
___
Python-Dev
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
Bill Janssen wrote:
Yeah, but you can't do more complicated expressions that way, like
any(lambda x: x[3] == thiskey)
Not /quite/ sure what this is intended to mean, but most likely,
you meant
any(x[3]==thiskey for x in seq)
I think it makes a lot of sense for any and all to
sorry if this came up before, but I tried searching the archives and
found nothing. It would be really nice if new builtin truth functions
in 2.5 took a predicate argument(defaults to bool), so one could
write, for example:
seq = [1,2,3,4,5]
if any(seq, lambda x: x==5):
...
which is