Search⌘ K

Len and Sum

Explore how the len and sum functions operate as reducing functions in Python. Understand their use cases, limitations with lazy iterables and strings, and learn best practices for summing lists and flattening nested lists to simplify data processing.

We'll cover the following...

Reducing functions

In the earlier chapter on Iterators, we divided the built-in iterator functions into groups:

  • Transforming functions
  • Reducing functions
  • Converting functions
  • Primitive functions

In this chapter, we will cover the reducing functions.

A reducing function takes all the values from an iterable and reduces them to a single representative value. For example, ...