-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkata26.py
71 lines (28 loc) · 950 Bytes
/
kata26.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
64
65
66
67
68
69
70
71
def solution(args):
lst=[]
i=args[0]
while i in args:
n= args.index(i)
if i+1 not in args:
lst.append(str(i))
if n<(len(args)-1):
i = args[n + 1]
else:
break
else:
lst2 = []
lst2.append(i)
while i + 1 in args:
lst2.append(i + 1)
i = i + 1
if len(lst2) == 2:
j = f"{str(lst2[0])},{str(lst2[-1])}"
else:
j = f"{str(lst2[0])}-{str(lst2[-1])}"
lst.append(j)
if args.index(lst2[-1]) < (len(args) - 1):
i = args[args.index(lst2[-1]) + 1]
else:
break
return ",".join(lst)
print(solution([-6,-3,-2,-1,0,1,3,4,5,7,8,9,10,11,14,15,17,18,19,20]))