فهرست منبع

Merge pull request #6 from lihan/patch-1

Simplified the count_to function
Sakis Kasampalis 12 سال پیش
والد
کامیت
eb397c5994
1فایلهای تغییر یافته به همراه2 افزوده شده و 2 حذف شده
  1. 2 2
      iterator.py

+ 2 - 2
iterator.py

@@ -4,8 +4,8 @@
 def count_to(count):
 def count_to(count):
     """Counts by word numbers, up to a maximum of five"""
     """Counts by word numbers, up to a maximum of five"""
     numbers = ["one", "two", "three", "four", "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
         yield number
 
 
 # Test the generator
 # Test the generator