Quellcode durchsuchen

Merge pull request #6 from lihan/patch-1

Simplified the count_to function
Sakis Kasampalis vor 12 Jahren
Ursprung
Commit
eb397c5994
1 geänderte Dateien mit 2 neuen und 2 gelöschten Zeilen
  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