Skip to content

Instantly share code, notes, and snippets.

@ptn
Created March 21, 2014 19:50
Show Gist options
  • Save ptn/9694817 to your computer and use it in GitHub Desktop.
Save ptn/9694817 to your computer and use it in GitHub Desktop.
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