Build a basic key-value store class with a Python dict as the underlying storage.
You'll implement four methods:
put(key, value) — store a valueget(key) — retrieve a value, or None if missingdelete(key) — remove a key, return True if it existedsize() — number of keysOnce the tests pass, you'll have the minimal surface area of a KV store. The next steps add overwrite semantics, TTL, and an HTTP layer.
class KeyValueStore:
"""A simple in-memory key-value store."""
def __init__(self):
# TODO: Initialize the underlying storage
pass
def put(self, key, value):
"""Store a key-value pair."""
# TODO: Implement this
pass
def get(self, key):
"""Retrieve a value by key. Return None if not found."""
# TODO: Implement this
pass
def delete(self, key):
"""Delete a key. Return True if deleted, False if not found."""
# TODO: Implement this
pass
def size(self):
"""Return the number of keys in the store."""
# 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.
Build a basic key-value store class with a Python dict as the underlying storage.
You'll implement four methods:
put(key, value) — store a valueget(key) — retrieve a value, or None if missingdelete(key) — remove a key, return True if it existedsize() — number of keysOnce the tests pass, you'll have the minimal surface area of a KV store. The next steps add overwrite semantics, TTL, and an HTTP layer.
Press Run Tests or ⌘↩ to check your solution.