Re: [Python-Dev] Any reason that any()/all() do not take a predicateargument?

2006-04-15 Thread Brian Quinlan
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

Re: [Python-Dev] Any reason that any()/all() do not take a predicateargument?

2006-04-15 Thread Martin v. Löwis
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

Re: [Python-Dev] Any reason that any()/all() do not take a predicateargument?

2006-04-15 Thread Bill Janssen
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

Re: [Python-Dev] Any reason that any()/all() do not take a predicateargument?

2006-04-15 Thread Martin v. Löwis
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

Re: [Python-Dev] Any reason that any()/all() do not take a predicateargument?

2006-04-13 Thread Andrew Koenig
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