Выдает ошибку list out of range. Помогите исправить и посоветуйте как ускорить
dim_hand = 5
num_letters = 400
def punti(w):
somma = 0
for i in range(len(w)):
if w[i] in 'eaionrtlsu':
p = 1
elif w[i] in 'dg':
p = 2
elif w[i] in 'bcmp':
p = 3
elif w[i] in 'fhvwy':
p = 4
elif w[i] in 'k':
p = 5
elif w[i] in 'jx':
p = 8
elif w[i] in 'qz':
p = 10
somma = somma + p
return(somma)
hand = [dim_hand, dim_hand, dim_hand, dim_hand]
pun = [0, 0, 0, 0]
g = []
g.append(g1)
g.append(g2)
g.append(g3)
g.append(g4)
num_letters = num_letters - (4 * dim_hand)
lun = len(g1) + len(g2) + len(g3) + len(g4)
for i in range(lun):
for j in range(len(g)):
word = g[j][i]
s = punti(word)
pun[j] = pun[j] + s
if num_letters >= 0:
if num_letters >= dim_hand :
dim = dim_hand
else:
dim = dim - (dim_hand - num_letters)
else:
dim = dim_hand - len(word)
if num_letters < 0:
num_letters = 0
hand[j] = dim
num_letters = num_letters - len(word)
if hand[j] == 0:
for t in range(len(pun)):
pun[t] = pun[t] - (hand[t] * 3)
print(pun)