Created
March 29, 2011 13:41
-
-
Save jgrgt/892376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def i_am_wrong(d=dict()): | |
key = "results" | |
if key not in d: | |
d[key] = list() | |
d[key].append("Hi!") | |
return d | |
print "No problems:" | |
print i_am_wrong(dict()) | |
print i_am_wrong(dict()) | |
print i_am_wrong(dict()) | |
print "But what if we do not pass d?" | |
print i_am_wrong() | |
print i_am_wrong() | |
print i_am_wrong() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% python do_not_use_dict_as_arg.py | |
No problems: | |
{'results': ['Hi!']} | |
{'results': ['Hi!']} | |
{'results': ['Hi!']} | |
But what if we do not pass d? | |
{'results': ['Hi!']} | |
{'results': ['Hi!', 'Hi!']} | |
{'results': ['Hi!', 'Hi!', 'Hi!']} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution: