Some additional tidbits.
After learning built-in help as suggested by metulburr you can turn to Python documentation for more information: all(), any()
You can learn that both functions have short-circuiting feature meaning that they will stop when first False is encountered (function all) or when first True (any).
As somewhat practical example is determining whether string is valid DNA sequence.
After learning built-in help as suggested by metulburr you can turn to Python documentation for more information: all(), any()
You can learn that both functions have short-circuiting feature meaning that they will stop when first False is encountered (function all) or when first True (any).
As somewhat practical example is determining whether string is valid DNA sequence.
>>> allowed = ['a', 'c', 'g', 't'] >>> dna = 'tatcagaaaacacgcgcttaagtgagcggaacgggtggaacaaggttgta' >>> all(char in allowed for char in dna) True >>> dna = 'tatcagaaaacacgcgcttaagtgagcggaacgggtggaacaagguttgta' # there is 'u' >>> all(char in allowed for char in dna) FalseIs there any number in sequence which is divisible both with 2 and 3:
>>> lst = [2, 3, 7, 11, 18, 20] >>> any(num % 2 == 0 and num % 3 == 0 for num in lst) True
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.