I was wondering: would it be possible to access dict values with uncomplete keys (as long as there are not more than one entry for a given string)? For example:
You are not suggesting a coherent API:
my_dict['']
? You don't have a one-to-one mapping.str
?Another reason you can't have it directly, even for strings and assuming you always return a list, is because Python's dict
is implemented using a hash table, and it will map xy
and xz
to unrelated cells in the table.
So, going the other way: such a lookup to would mean going for a slower implementation of dict
, (which doesn't make sense, optimizing for an uncommon use) or being as slower as a full scan - which you may as well write it by hand, as it is not that common to be worth a dedicated convenience method.