Lesson 11.8
Four built-in functions that make code shorter:
| Function | What it does |
|---|---|
any(...) |
at least one True |
all(...) |
all are True |
zip(a, b) |
pairs from two lists |
enumerate(a) |
pairs of "number, value" |
print(any(s == 5 for s in scores))
print(all(s >= 3 for s in scores))
for name, age in zip(names, ages):
print(name, age)
any([4, 5]) is a mistake in meaning: numbers are not True/False, comparisons are needed.
enumerate has start=1 when numbering should begin at one.
The check sets the list of numbers scores, the names names and the ages ages. Print:
any item of scores is target;all the numbers are at least lowest;name age from zip;number name from enumerate, numbered from 1.any and all take a generator of conditions.
any needs the comparison s == target, all needs s >= lowest.
zip gives pairs, enumerate a "number and item" pair; numbering from one
comes from start=1.