-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
43 lines (37 loc) · 1.03 KB
/
utils.py
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
import typing
def permutations_of(
*args: typing.Any,
) -> typing.Generator[typing.Tuple[typing.Any, ...], None, None]:
values = set(args)
for i in values:
remaining = values - {i}
if remaining:
for objects in permutations_of(*remaining):
yield (i, *objects)
else:
yield i,
def deep_loop(
*args: typing.Iterable,
) -> typing.Generator[typing.Tuple[typing.Any, ...], None, None]:
for i in args[0]:
if args[1:]:
for objects in deep_loop(*args[1:]):
yield (i, *objects)
else:
yield i,
def float_range(
start: float, stop: float = None, step: float = 1, /
) -> typing.Generator[float, None, None]:
if stop is None:
stop = start
start = 0
if step == 0:
raise ValueError("step cannot be negative")
if step < 0:
while start > stop:
yield start
start += step
else:
while start < stop:
yield start
start += step