def value_by_key_prefix(d, partial):
    matches = [val for key, val in d.items() if key.startswith(partial)]
if not matches:
    raise KeyError(partial)
if len(matches) > 1:
    raise ValueError('{} matches more than one key'.format(partial))
return matches[0]
Accessing Python dict values with the key start characters