-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitertools.py
More file actions
57 lines (47 loc) · 1.07 KB
/
itertools.py
File metadata and controls
57 lines (47 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def accumulate(iterable, func=operator.add, *, init=None):
it = iter(iterable)
tot = init
if init is None:
try:
tot = next(it)
except StopIteration:
return
yield tot
for e in it:
tot = func(tot, e)
yield tot
def chain(*iterables):
for i in iterables:
for j in i:yield j
def count(start,step=1):
while 1:
yield start
start += step
def compress(data,selector):
return (d for d, s in zip(data, selector) if s)
def cycle(iterable):
sav = []
for e in iterable:
yield element
sav.append(e)
while saved:
for e in sav:
yield e
def filterfalse(predicate, list):
if predicate is None:
predicate = bool
for x in list:
if not predicate(x):yield x
def repeat(object, times=None):
if times is None:
while True:
yield object
else:
for i in range(times):
yield object
def starmap(func,i):
for args in i:yield func(*args)
def takewhile(func,i):
for j in i:
if func(j):yield j
else:break