Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 6 Online
OpenStudy (anonymous):

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 Does the return function return the key of d or value of d? and WHY? Thanks!

OpenStudy (turingtest):

what is s? a list of some sort?

OpenStudy (anonymous):

s is a list of strings, d is dictionary.

OpenStudy (turingtest):

this function returns d, the dictionary, after some modification to the original input. You should break up the code and comment on each section to walk through it more clearly so you can see exactly what it does.

OpenStudy (turingtest):

def f(s, d): for k in d.keys(): # iterates over a list of the keys of the dict d[k] = 0 # sets each value for each key to 0 for c in s: #iterates over each element in the list of strings if c in d: #if an element in the list is a key in the dict d[c] += 1 #add 1 to the value in the dict for that key else: d[c] = 0 #otherwise add that key to the dict and set it to 0 return d #return the dictionary

OpenStudy (turingtest):

so it returns neither the keys, nor values of d, but d itself in its entirety, albeit modified

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Arriyanalol: i need help
16 hours ago 7 Replies 1 Medal
Arriyanalol: CONGRATS to me
19 hours ago 8 Replies 2 Medals
Legomaster346: What colleges are good that are near Arab Alabama?
1 week ago 5 Replies 0 Medals
Arriyanalol: i need help
1 week ago 6 Replies 2 Medals
Arizona: does anyone know the percentage rate of 30,000 and 40,000
1 week ago 0 Replies 0 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!