Overwrite and List Keys

Step 2 β€” Overwrite and List Keys

Now extend the store with two more methods:

  • keys() β€” return a list of all keys
  • exists(key) β€” return True if the key exists

Also confirm that put on an existing key overwrites the value, not adds a duplicate.

Hints
Starter code
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
Write it on a laptop

The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.