From the course: Python: Design Patterns (2021)

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Iterator example

Iterator example

- [Instructor] Now, let's define our iterator. We start with creating a list. The list contains German words counting up to five. Here, we'll use Python's built-in iterator. The iterator will create tuples consisting of pairs of numbers and equivalent German words. For example, one and the German word, eins. The tuple here means a pair. One and eins that's a tuple. Two and zwei. That's another tuple. The built-in iterator provided by Python is zip. We have to generate numbers up to five. So we use the function range here. So type range. The argument of the function is the number of German words to display, which is count. So type count. This is the first argument of the zip iterator. The second argument is the list itself. The numbers in German is our list. Type numbers in German. The range function here is important, because it allows us to know up to what number we can count. We use a variable called iterator…

Contents