Re: why any( ) instead of firsttrue( ) ?

2010-06-10 Thread Tim Roberts
danieldelay danielde...@gmail.com wrote: Does GVR prefers beauty to power ? Not in the beginning, but in recent years things are tending this way. And, frankly, I don't think that's a Bad Thing at all. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. --

Re: why any( ) instead of firsttrue( ) ?

2010-06-09 Thread Raymond Hettinger
On Jun 8, 2:16 pm, danieldelay danielde...@gmail.com wrote:    def firsttrue(iterable):      for element in iterable:          if element:              return element      return None This function firsttrue( ) could probably be used anywhere any( ) is used, but with the ability to

Re: why any( ) instead of firsttrue( ) ?

2010-06-09 Thread danieldelay
Le 09/06/2010 08:54, Raymond Hettinger a écrit : next(ifilter(None, d), False) Good, this is rather short and does the job !... I should try to use more often this itertools module. Thanks Daniel -- http://mail.python.org/mailman/listinfo/python-list

why any( ) instead of firsttrue( ) ?

2010-06-08 Thread danieldelay
Hi, I find very useful in python the ability to use a list or number x like a boolean : if x : do something So I don't understand why was introduced the any( ) function defined as : def any(iterable): for element in iterable: if element: return True

Re: why any( ) instead of firsttrue( ) ?

2010-06-08 Thread Ian Kelly
On Tue, Jun 8, 2010 at 3:16 PM, danieldelay danielde...@gmail.com wrote: This function firsttrue( ) could probably be used anywhere any( ) is used, but with the ability to retrieve the first element where bool(element) is True, which may be sometimes usefull. I suppose that there is a reason

Re: why any( ) instead of firsttrue( ) ?

2010-06-08 Thread danieldelay
Le 09/06/2010 00:24, Ian Kelly a écrit : Because it was designed as a replacement for reduce(lambda x, y: x or y, iterable). The problem arises when the iterable is empty. What false value should be returned? If the iterable is a sequence of bools, then None doesn't fit. If the iterable is a

Re: why any( ) instead of firsttrue( ) ?

2010-06-08 Thread MRAB
danieldelay wrote: Le 09/06/2010 00:24, Ian Kelly a écrit : Because it was designed as a replacement for reduce(lambda x, y: x or y, iterable). The problem arises when the iterable is empty. What false value should be returned? If the iterable is a sequence of bools, then None doesn't fit.

Re: why any( ) instead of firsttrue( ) ?

2010-06-08 Thread Tim Chase
On 06/08/2010 06:18 PM, MRAB wrote: danieldelay wrote: firsttrue(line.strip() for line in '\n\n \n CHEERS \n'.split('\n')) Should 'firsttrue' return None? Surely, if none are true then it should raise an exception. which can fairly elegantly be written with stock-Python as # try:

Re: why any( ) instead of firsttrue( ) ?

2010-06-08 Thread Carl Banks
On Jun 8, 4:08 pm, danieldelay danielde...@gmail.com wrote: Le 09/06/2010 00:24, Ian Kelly a crit : Because it was designed as a replacement for reduce(lambda x, y: x or y, iterable).  The problem arises when the iterable is empty.  What false value should be returned?  If the iterable is