Bläddra i källkod

Simplified the count_to function

It is preferred to use enumerate() than zip()
lihan 12 år sedan
förälder
incheckning
1ccc5ed90a
1 ändrade filer med 2 tillägg och 2 borttagningar
  1. 2 2
      iterator.py

+ 2 - 2
iterator.py

@@ -4,8 +4,8 @@
 def count_to(count):
     """Counts by word numbers, up to a maximum of five"""
     numbers = ["one", "two", "three", "four", "five"]
-    # The zip keeps from counting over the limit
-    for number, pos in zip(numbers, list(range(count))):
+    # enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence
+    for pos, number in enumerate(numbers):
         yield number
 
 # Test the generator