Skip to Content
Secret Recipes of the Python Ninja
book

Secret Recipes of the Python Ninja

by Cody Jackson
May 2018
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 37m
English
Packt Publishing
Content preview from Secret Recipes of the Python Ninja

Infinite iterators

Infinite iterators return values repeatedly until a terminating condition is reached:

  1. The count(start=0, step=1) function returns evenly spaced values that start at the start argument provided. Stepping is provided to allow skipping values. This function is frequently used with map() to generate consecutive data points. When used with zip(), it can be used to add sequence numbers:

    • In this example, we import the count() function from the itertools module in line 54.
    • In line 55, we create a counting loop, starting with the integer 5 and a stepping value of 5, that is, counting by fives. When the count exceeds 50, the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Expanding World of Python

The Expanding World of Python

Dane Hillard

Publisher Resources

ISBN: 9781788294874Supplemental Content