-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
64 lines (59 loc) · 1.61 KB
/
visualize.py
File metadata and controls
64 lines (59 loc) · 1.61 KB
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
from collections import Counter
def visualize(tuple, bar_char='₽'):
c = sorted(Counter(tuple).most_common())
string_sum = ''
max = 0
string1 = ''
string2 = ''
for x in c:
if x[1] > max:
max = x[1]
if x == c[-1]:
string1 = string1 + '--'
else:
string1 = string1 + '---'
whitespace = ' '
if x == c[-1]:
whitespace = ''
if len(str(x[0])) == 1:
string2 = string2 + str(x[0]) + ' ' + whitespace
else:
string2 = string2 + str(x[0]) + '' + whitespace
j = 0
while j <= max:
i = 0
string = ''
whitespace = ' '
while i < len(c):
if i == len(c) - 1:
whitespace = ''
if c[i][1] == max - j:
string = string + str(c[i][1]) + ' ' + whitespace
elif c[i][1] < max - j:
string = string + ' ' + whitespace
elif c[i][1] > max - j:
string = string + bar_char * 2 + '' + whitespace
i += 1
if string != '':
string_sum = string_sum + string + '\n'
j += 1
string_sum = string_sum + string1 + '\n' + string2
return string_sum
MONEY = (
1, 20, 2, 5, 20,
3, 5, 2, 10, 2,
20, 2, 20, 1, 2,
1, 1, 2, 10, 20, 3,
)
print(visualize(MONEY))
print("""
6
₽₽ 5
4 ₽₽ ₽₽
₽₽ ₽₽ ₽₽
₽₽ ₽₽ 2 2 2 ₽₽
₽₽ ₽₽ ₽₽ ₽₽ ₽₽ ₽₽
₽₽ ₽₽ ₽₽ ₽₽ ₽₽ ₽₽
-----------------
1 2 3 5 10 20
"""[1:-1])