  Bits and Pieces of Python  “Man tager om man så hafva kan…”
Creating an Endless Sequence  This example shows a simple and
straightforward way to do this, using a custom sequence wrapper.
This works in all versions of Python.  Example: creating an
endless sequence class over_and_over_again:     def
__init__(self, seq):         self.seq = seq         self.len =
len(seq)     def __getitem__(self, index):         return
self.seq[index % self.len]  # zip stops when the shortest
sequence ends print zip(range(12), over_and_over_again("spam"))
In more recent versions, it’s possible to do the same thing in
more “interesting” ways, using iterators and/or generators. More
on that later.  Populating a Dictionary Inside a Lambda  In the
following example, the “for k, v in x” part represents any
function or expression returning a sequence of key/value pairs,
where all keys are unique. The goal is to turn this into a
dictionary. In 2.2, this is easy. In 2.1, it’s possible to do
this on a single line, without help from o