Answer the question
In order to leave comments, you need to log in
How to remove the error RuntimeError: dictionary changed size during iteration?
def top3(st):
st = st.lower()
sp = {}
for i1 in 'qwertyuiopasdfghjklzxcvbnm':
if st.find(i1) != -1:
sp[i1] = st.count(i1)
a = 3
while a > 0:
for i2 in sp:
m = max(sp.values())
if sp[i2] == m:
print(str(i2) + ' - ' + str(sp[i2]))
sp. pop(i2)
print(sp)
a -= 1
top3('hhhhhgggl')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question