In this video, Kathryn teaches you how to iterate through data with Python's itertools module. Learn how to write functions that count infinitely, cycle through a given input, and repeat a value an infinite amount of times.
- [Narrator] The Itertools module…allows us to iterate and go through…our data in different ways.…And so to use it, we have to import it.…We'll go import Itertools.…The first thing we're going to do…with this module is create an infinite counting mechanism.…And so to do this, we are going to use a for-loop.…And so we're going to go for x in Itertools.count…so using the count method, and our input is going to be 50.…And so here, we're going to start our infinite counting at 50.…
And it's going to count until the end of time.…And so if we go print x and run this,…it's going to continue to count, and it's…probably going to crash your computer,…unless you physically stop it.…And here it'll have a keyboard interrupt…because I stopped it in the editor.…And so what you can do to prevent it…from counting infinitely, but still…counting as much as you want,…you can have an if statement here with…if x equals 80, or whatever number you'd like,…and then you can have a break statement.…Or it could be an if statement…checking another condition that also…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
Learning the Standard PHP Librarywith David Powers3h 24m Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.