0

Found a way that can possibly allow me to get the keys of my dictionary using value with this : mydic.keys()[mydic.values().index(value-I-use)]

in this code :

def déchiffrement(code,dico):
    taille3 = len(code)
    décodé = []
    for i in range(taille3):
        décodé.insert(i, dico.keys()[dico.values().index(code[i])])
    return décodé

"dico" is a dictionary looking like this : dico = {"A":[1,9],"B":["12,19].... "Z":[78, 108]} and "code" is a list of numbers that corresponds to a letter. The numbers in dico are never the same.

Problem is : I get a AttributeError: 'dict_values' object has no attribute 'index' which I don't understand because this code seems to work on other people's codes.

Raëgan
  • 25
  • 5
  • Your question is unclear. If you want to get a proper answer you need to update your question with the code that you have tried so far or a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Mazdak Mar 18 '16 at 18:27
  • What version of Python are you using? `dict.values` used to return a list, but as of Python 3.0 it returns a [dictionary view](https://docs.python.org/3.0/library/stdtypes.html#dictionary-view-objects). You'll need to convert it to a list if you want to use `__getitem__`. – dirn Mar 18 '16 at 21:57

0 Answers0