-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumbers.py
63 lines (52 loc) · 1.44 KB
/
numbers.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Examples Numbers."""
import netports
# Sort numbers and removes duplicates
range_o = netports.parse_range("3\t- 5, 1 , 3-5\t,1\n")
print(f"{range_o!r}")
print(range_o.line)
print(range_o.numbers())
# Range("1,3-5")
# 1,3-5
# [1, 3, 4, 5]
print()
# Range with custom splitter and range_splitter
range_o = netports.parse_range("1 3 to 5 1 3 to 5", splitter=" ", range_splitter=" to ")
print(f"{range_o!r}")
print(range_o.line)
print(range_o.numbers())
# Range("1 3 to 5", splitter=" ", range_splitter=" to ")
# 1 3 to 5
# [1, 3, 4, 5]
print()
# Converts unsorted range to sorted List[int] without duplicates
ports = netports.inumbers("3-5,1,3-5,1")
print(ports)
# [1, 3, 4, 5]
ports = netports.inumbers(["3-5,1", "3-4", "1"])
print(ports)
# [1, 3, 4, 5]
ports = netports.inumbers([3, 4, 5, 1, 3, 4, 5, 1])
print(ports)
# [1, 3, 4, 5]
print()
# Converts unsorted range to List[int] with custom splitters
ports = netports.inumbers("3 to 5 1 4 to 5 1", splitter=" ", range_splitter=" to ")
print(ports)
# [1, 3, 4, 5]
print()
# Converts unsorted range to sorted str without duplicates
ports = netports.snumbers("3-5,1,3-5,1")
print(ports)
# 1,3-5
ports = netports.snumbers(["3-5,1", "3-4", "1"])
print(ports)
# 1,3-5
ports = netports.snumbers([3, 4, 5, 1, 3, 4, 5, 1])
print(ports)
# 1,3-5
print()
# Converts unsorted range to str with custom splitters
ports = netports.snumbers("3 to 5 1 4 to 5 1", splitter=" ", range_splitter=" to ")
print(ports)
# 1 3 to 5
print()