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 - Python Tutorial
From the course: Python: Design Patterns (2021)
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
-
-
-
-
-
-
(Locked)
Observer1m 5s
-
(Locked)
Observer example6m 22s
-
(Locked)
Visitor56s
-
(Locked)
Visitor example6m 42s
-
(Locked)
Iterator1m 15s
-
(Locked)
Iterator example4m 32s
-
(Locked)
Strategy40s
-
(Locked)
Strategy example5m 44s
-
(Locked)
Chain of responsibility1m 4s
-
(Locked)
Chain of responsibility example5m 57s
-
(Locked)
-
-