any() and all() on empty list?
Piet van Oostrum
piet at cs.uu.nl
Mon Apr 10 09:17:29 EDT 2006
>>>>> "Steve R. Hastings" <steve at hastings.org> (SRH) wrote:
[snip]
>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].
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list