6) Consider the following code:
def f(s, d):
for k in d.keys():
d[k] = 0
for c in s:
if c in d:
d[c] += 1
else: d[c] = 0
return d
def addUp(d):
result = 0
for k in d:
result += d[k]
return result
d1 = {}
d2 = d1
d1 = f('abbc', d1)
print addUp(d1)
d2 = f('bbcaa', d2)
print addUp(d2)
print f('', {})
print result
6.1) What does it print? (9 points)
Solution :
1
5
{}
I've absolutely no idea how those answers came. Could someone help me at least with the begining so I can figure it out ? Especially the line :
for k in d.keys():
d[k] = 0
d is an empty dic so it has no keys ? I'm really confused lol.

New Topic/Question
Reply


MultiQuote



|