This commit is contained in:
2026-01-03 12:35:31 +03:00
parent 9afd997a2e
commit d66ec02d68
2 changed files with 35 additions and 0 deletions

11
chunker.py Normal file
View 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
View 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")