Relative Content

Tag Archive for pythondictionaryiteration

what would the pythonic version be of this code

i’m working on something silly, it’s just a fun little encoding thing to mess around and get back in the spirit after being too busy to code for a while. i realised while writing it that the only strategy i’ve found to work for using dictionaries in this way is completely unpythonic, but i specifically remember scouring the internet while learning this method. i think i had to come up with this myself, because the easiest way i’d found otherwise was just to iterate and check through the dict.values() list, which seemed silly. i basically just want to be able to access not only values by key, but keys by value. i feel like making two dictionaries is just inefficient, but so is the iterate-and-check process. is there some better way that i’m missing? here’s an example snippet of some code: