On 6 September 2017 at 08:39, edmundo pierre via Tutor <tutor@python.org> wrote: > Hi Python, > I am trying to make a french to English dictionary. First of all, I made a > dictionary with keys and values. Then I asked the user to enter a letter. If > the letter correspond to the Keys, my print function should display the Key > and value. But my code below, could not . Thank you! > > List ={"le":"…"} (it”s called dict, or dictionary, and “List”/“dict” are not good variable names)
> keys = List.keys()print(keys) > a = str(input("")) > if 'a' in keys: print(a + ":"+ List['a'])else: print("impossible") You’re trying to find the letter 'a' and print it, you aren’t using the variable a. Don’t put it in quotes. So, do it like this: data = {"le": "…"} print(data.keys()) search_key = str(input("> ")) if search_key in data: print(search_key, ":", data[search_key]) else: print("Not in dictionary.") (I also cleaned it up a little) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor