Skip to content

Commit e18fa59

Browse files
author
Joseph Luce
authored
Update itertools.md
1 parent 91e7b06 commit e18fa59

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: pythonic/itertools.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# Itertools
22
This section will go over a few tools in python 3's itertools library.
33

4+
## Iterables vs. Iterators
5+
6+
Before we begin, you can't understand itertools unless you understand iterators and iterables.
7+
8+
### Iterables
9+
10+
### Iterators
11+
Iterators is an object which can iterate over an iterable.
12+
You can create an iterator with the **iter()** method.
13+
You can iterate by implementing the **__next__()** method, this returns the next item in the object.
14+
15+
When you use a for loop, you are actually using an iterator. An iterator is created for you and loop across your iterable.
16+
When an iterator reaches the end of the list, it will automatically throw a StopIteration exception.
17+
The for loop catches that exception and exits gracefully.
18+
419
## count()
520

621
## cycle()

0 commit comments

Comments
 (0)