Python Naming Conventions for Dictionaries/Maps/Hashes
key_to_value
, for example surname_to_salary
may be useful when there are closely interrelated maps in code: a to b, b to a, c to b etc.
I never seem to name them anything like what you proposed (i.e. keeping one way). It just seems to be much more clear when I can find a "proper name" for the hash. It might be "person_details" or "file_sizes" or "album_tracks" etc. (although the last 2 seem to have key_value names, first one a bit less). In rare cases, it will be key_value_map
, or value_key_map
if it's important that it's a map.
I would never assume any naming scheme for that. Sometimes the values are what you're after, sometimes the keys. My preference is "a natural name".
values_by_key
- it is not so confusing as
value_key_map
: you can't confuse what isvalue name and what is key name - it doesn't name the type directly -- python style naming