>>> from itertools import tee
>>> r = xrange(10)
>>> i1, i2 = tee(r, 2)
>>> i1
<itertools.tee object at 0x0272B940>
>>> i2
<itertools.tee object at 0x0272BA58>
>>> list(i1)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(i1)
[]
>>> i2
<itertools.tee object at 0x0272BA58>
>>> list(i2)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(i2)
[]
>>> from itertools import islice
>>> r = xrange(10)
>>> s = islice(r, 3, 5)
>>> s
<itertools.islice object at 0x02737060>
>>> list(s)
[3, 4]
>>> d = {'a': 21, 'b': 5, 'c': 7, 'd': 5, 'e': 10}
>>> def v1(d=d):
return {k: v for k, v in d.items() if d.values().count(v) == 1}
>>> def v2(d=d, cnt=d.values().count):
{k: v for k, v in d.items() if cnt(v) == 1}
>>> def v3(d=d, cnt=d.values().count):
{k: v for k, v in d.viewitems() if cnt(v) == 1}
>>> from timeit import timeit
>>> timeit(v1, number=1000000)
9.940651956859298
>>> timeit(v2, number=1000000)
6.061919530989137
>>> timeit(v3, number=1000000)
4.280532062150144