I thought I'd address a few things.
ZipExhausted
It is defined in the code:
class ZipExhausted(Exception):
pass
So, it's a class that inherits from Exception
. Which means it can be used as an exception.
pass
means that this class doesn't define anything by itself, it's really a standard exception, with a different name. Why a different name ? So that you can catch it specifically.
-
raise
This simply raise an exception. You raise your own exceptions, so that they can be handled somewhere else. It's basically a "return error".
-
yield
This one is a bit more complicated. It has to do with generators.
Simply put, it's a return that keeps track of where the function's execution was when it returned.
Let's say you have this function:
def get_numbers():
yield 1
yield 2
yield 3
Now, when you call this function, it will return a generator that can produce the numbers 1, 2 and 3.
ie:
for n in get_numbers():
print n
will print
1
2
3
sum(foo())
will return 6.
etc.
repeat()
This produces a repeat
object, which is basically a generator that repeats something.
for x in repeat('foo', 3):
print x
will print
foo
foo
foo
chain()
That simply chains things in a sequence. It sorts of 'flattens' it.
list(chain([1, 2], [3, 4], [5, 6]))
returns [1, 2, 3, 4, 5, 6]
. I used list
because chain
itself returns, again, a generator (or, more accurately, a chain
object, but, just like repeat
objects, you can use it like a generator)