Created
March 21, 2014 19:50
-
-
Save ptn/9694817 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
class NativeDictionary: | |
def __init__(self): | |
self.dictionary = {} | |
def add_key_value_pair(self, key, value): | |
self.dictionary[key] = value | |
def get_value(self, key): | |
return self.dictionary[key] | |
def remove_key(self, key): | |
del self.dictionary[key] | |
d = NativeDictionary() | |
#DONT CHANGE | |
d.add_key_value_pair('gina', 4) # d['gina'] = 4 | |
print d.get_value('gina') # => 4 | |
try: | |
d.get_value('pablo') # ERROR! | |
except KeyError: | |
print 'it raised an error' | |
d.add_key_value_pair('pablo', 2) | |
print d.get_value('pablo') # => 2 | |
d.remove_key('pablo') | |
d.get_value('pablo') # ERROR! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment