Python function not returning correct output
Trying to use python to change the value associated to a key in a
dictionary and it's not returning the correct output
def fetchAndReplace(dictionary,key,newValue):
keys = dictionary.keys()
for i in keys:
if i == key:
print dictionary[key]
dictionary[key] = newValue
return
else:
return "Nothing"
When I call this one a dictionary {'x':3,'y':2}, with x for key and 6 for
newValue It returns the string nothing, which it shouldn't. I can't find
anything wrong with my code so if you could point out the mistake I'm
overlooking I'd appreciate it.
No comments:
Post a Comment