2
Providing iterator functions that are not in all version of Python we support.
3
Where possible, we try to use the system-native version and only fall back to
4
these implementations if necessary.
9
def compat_tee(iterable):
11
Return two independent iterators from a single iterable.
13
Based on http://www.python.org/doc/2.3.5/lib/itertools-example.html
15
# Note: Using a dictionary and a list as the default arguments here is
16
# deliberate and safe in this instance.
17
def gen(next, data={}, cnt=[0]):
19
for i in itertools.count():
21
item = data[i] = next()
26
next = iter(iterable).next
27
return gen(next), gen(next)
29
def groupby(iterable, keyfunc=None):
31
Taken from http://docs.python.org/lib/itertools-functions.html
35
iterable = iter(iterable)
37
lastkey = keyfunc(l[0])
48
# Not really in itertools, since it's a builtin in Python 2.4 and later, but it
49
# does operate as an iterator.
51
for index in xrange(len(data)-1, -1, -1):
54
if hasattr(itertools, 'tee'):
58
if hasattr(itertools, 'groupby'):
59
groupby = itertools.groupby
62
"A implementation independent way of checking for iterables"
71
"A naive implementation of sorted"
72
out_value = in_value[:]