Previous chapters mentioned iterables several times, and we know that lists, tuples, and many other built-in data types are iterables. But we haven’t explicitly defined the concept of iterables. We say that these data types are iterables, but we haven’t discussed why. In this chapter, you’ll find out how they constitute iterables. More importantly, we’ll explore how we can create the most common data models, such as lists and dictionaries, from other iterables by using constructors and comprehensions.
One essential mechanism for Python or any other programming language to perform repetitive work is for-loop iterations (or while loop, with for loops being more prevalent). In each iteration, the same operations can be applied to each item of the iterables. We have a variety of ways to improve the performance of for loops by applying built-in functions, such as enumerate and zip, and by using optional state-ments, including break and continue. In this chapter, you’ll learn about these topics.