Record Store
MetaPhone screenMedium
Build an in-memory record store as a class RecordStore. A record is addressed by a key and holds named fields, each holding a string value. Every test creates one RecordStore() and runs a sequence of calls, checking every return value; methods that return nothing are checked as None. A test only calls methods introduced so far.
Part 1: Set, get, delete
Implement set(key, field, value), which stores value under field of the record key, overwriting any previous value. get(key, field) returns the stored value, or None if the key or the field does not exist. delete(key, field) removes the field and returns True, or returns False if it does not exist. The empty string is a valid value.
- Example 1
- init
[]- operations
[["set",["u1","name","ann"]],["get",["u1","name"]],["get",["u1","age"]],["get",["u2","name"]],["set",["u1","name","bob"]],["get",["u1","name"]],["delete",["u1","age"]],["delete",["u1","name"]],["get",["u1","name"]]]- Output
[null,"ann",null,null,null,"bob",false,true,null]
Why:
getof an unset field or an unknown key returnsNone. The secondsetreplacesannwithbob. DeletingagereturnsFalsebecause it was never set; deletingnamereturnsTrue, after whichgetreturnsNone.
Constraints
1 <= number of operations <= 2 * 10^50 <= len(value) <= 1001 <= len(key) <= 1001 <= len(field) <= 100