-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
22 lines (18 loc) · 983 Bytes
/
interface.py
File metadata and controls
22 lines (18 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
num_of_rangs = 50
# возвращает строку с указанным кол-вом решеток(#)
def high_of_column(n):
s = ''
for i in range(n):
s += '#'
return s
# возвращает строку - гистограмму на основании словаря. кол-во решеток в гистограмме не более num_of_rangs
def histogram_of_symbols(dic):
ret_string = ''
l = sum([val for key, val in dic.items()])
for key, value in dic.items():
percents_of_syms = value / l # частота появления символа
num_of_cols = round(percents_of_syms * num_of_rangs) # "высота" колонки
ret_string += '{symbol}({per}%) : {column}\n'.format(symbol=key,
column=high_of_column(num_of_cols),
per=round(percents_of_syms, 5))
return ret_string