r/pythonhelp • u/aooooooooi • Nov 18 '21
HOMEWORK Python exercise
Hello,
I've got the following question in my programming class, but have no idea how to solve this. Could anyone kindly explain this with a solution ?
The following Python code fills an empty dictionary d step-by-step with information on how often each letter appears in tuple t and then returns the results as seen at the end. Fill in the gaps [ ]:
d = {}
t = ('M', 'I', 'S', 'S', 'I', 'S', 'S', 'I', 'P', 'P', 'I')
[ ] b in t:
if b not in :
d[b] = 1
[ ] :
d[b] = d[b] + [ ]
[ ] b, a [ ] d.items():
print ("t includes {} {}".format( [ ], [ ]))
Output:
t includes 1 M
t includes 4 I
t includes 4 S
t includes
1
u/htepO Nov 18 '21
It looks like a couple of for loops. What have you tried?