소스 검색

Simplified the count_to function

It is preferred to use enumerate() than zip()
lihan 13 년 전
부모
커밋
1ccc5ed90a
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  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