April 2018
Intermediate to advanced
408 pages
10h 42m
English
The len() and sum() functions provide two simple reductions—a count of the elements and the sum of the elements in a sequence. These two functions are mathematically similar, but their Python implementation is quite different.
Mathematically, we can observe this cool parallelism. The len() function returns the sum of ones for each value in a collection,
.
The sum() function returns the sum of x for each value in a collection,
.
The sum() function works for any iterable. The len() function doesn't apply to iterables; it only ...