any() and all() on empty list?

Ron Adam rrr at ronadam.com
Sat Apr 1 19:39:58 EST 2006


Steve R. Hastings wrote:

> Here is a function called "tally()".  It reduces a list to a dictionary
> of counts, with one key for each value from the list.  The value for
> each key is the count of how many times it appeared in the list.
>
 >
> def tally(seq, d=None):
>     if d == None:
>         d = {}
> 
>     for x in seq:
>         if x in d:
>             d[x] += 1
>         else:
>             d[x] = 1
>     return d
> 
> 
> This neatly replaces truecount(), and you can use it for other things as
> well.

     if True in talley(S): do_somthing()

Works for me...  ;-)


Cheers,
   Ron







More information about the Python-list mailing list