-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb_22.py
More file actions
40 lines (29 loc) · 1.04 KB
/
Prob_22.py
File metadata and controls
40 lines (29 loc) · 1.04 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
def sort_list_alphabetically(i_list):
new_list = []
while len(i_list) > 0:
min_string = i_list[0]
for i in range(len(i_list)):
if i_list[i] < min_string:
min_string = i_list[i]
leading_name = i_list.pop(i_list.index(min_string))
new_list.append(leading_name)
return new_list
def name_value(name):
ret_value = 0
for char in name:
ret_value += alphabetic_value_dict[char]
return ret_value
alphabetic_value_dict = {}
for i, code in enumerate(range(ord('A'), ord('Z') +1)):
alphabetic_value_dict[chr(code)] = (i+1)
name_list = []
with open("p022_names.txt", "r") as f:
read_string = f.read()
read_string = read_string.replace('"', '')
# print(read_string)
name_list += (read_string.split(","))
alphabetic_sorted_list = sort_list_alphabetically(name_list)
tot_value = 0
for i, name in enumerate(alphabetic_sorted_list):
tot_value += (i+1)*name_value(name)
print("Total Value of names:", tot_value)