+ etc
This commit is contained in:
11
chunker.py
Normal file
11
chunker.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
def chunker(it, n):
|
||||||
|
it = iter(it)
|
||||||
|
while 1:
|
||||||
|
chunk = tuple(x[1] for x in zip(range(n), it))
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
|
||||||
|
for chunk in chunker(range(25), 4):
|
||||||
|
print(list(chunk))
|
||||||
24
my_range_gen_3.py
Normal file
24
my_range_gen_3.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from operator import gt, lt
|
||||||
|
|
||||||
|
|
||||||
|
def my_range_gen(start, stop=None, step=1):
|
||||||
|
if stop is None:
|
||||||
|
start, stop = 0, start
|
||||||
|
|
||||||
|
if (
|
||||||
|
not step
|
||||||
|
or start == stop
|
||||||
|
or (step > 0 and start > stop)
|
||||||
|
or (step < 0 and start < stop)
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
x, op = start, start > stop and gt or lt
|
||||||
|
while op(x, stop):
|
||||||
|
yield x
|
||||||
|
x += step
|
||||||
|
|
||||||
|
|
||||||
|
for i in my_range_gen(20, 10, 3):
|
||||||
|
print(i)
|
||||||
|
print("End")
|
||||||
Reference in New Issue
Block a user