-
Notifications
You must be signed in to change notification settings - Fork 0
/
22.py
35 lines (33 loc) · 783 Bytes
/
22.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
def nameScores():
f = open('p022_names.txt')
l = []
pos = 'out'
name = ''
for line in f:
for char in line:
if char == '"' and pos == 'out':
pos = 'in'
elif char == '"' and pos == 'in':
pos = 'out'
l.append(name)
name=''
elif char != '"' and pos == 'in':
name+=char
l.sort()
# print l
namePosition = 1
nameCounter = 0
scores = []
totalScores = 0
lettersList = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for name in l:
for char in name:
nameCounter+=1+lettersList.index(char)
scores.append(namePosition*nameCounter)
totalScores+=(namePosition*nameCounter)
namePosition += 1
nameCounter = 0
# print scores
print totalScores
if __name__=='__main__':
nameScores()