any() and all() on empty list?

R

Ron Adam

Ron said:
Steve R. Hastings wrote:

if True in talley(S): do_somthing()

Works for me... ;-)


Cheers,
Ron

Actulley talley isn't needed for this...

if True in S: do_domething()


That's what I get for staying up way too late last night.

Cheers, Ron
 
P

Piet van Oostrum

Steve R. Hastings said:
SRH> vowels = frozenset("aeiouAEIOU")
SRH> f = open("a_file.txt") # note that f is an iterator
SRH> counts = tally(line[0] in vowels for line in f)

tally([line[0] in vowels for line in f])
SRH> # counts is a dict; counts.keys() == [False, True]

No guarantee about the order. It could be [True, False].
SRH> count_nonvowels, count_vowels = counts.values()

So you must use counts[False] and counts[True].
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top