Now extend the store with two more methods:
keys() β return a list of all keysexists(key) β return True if the key existsAlso confirm that put on an existing key overwrites the value, not adds a duplicate.
class KeyValueStore:
def __init__(self):
self._store = {}
def put(self, key, value):
self._store[key] = value
def get(self, key):
return self._store.get(key)
def delete(self, key):
if key in self._store:
del self._store[key]
return True
return False
def size(self):
return len(self._store)
def keys(self):
"""Return a list of all keys."""
# TODO: Implement this
pass
def exists(self, key):
"""Return True if key exists, False otherwise."""
# TODO: Implement this
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
Now extend the store with two more methods:
keys() β return a list of all keysexists(key) β return True if the key existsAlso confirm that put on an existing key overwrites the value, not adds a duplicate.
Press Run Tests or ββ© to check your solution.