[Python] How to check if a value exists in a dictionary?

Discussão em 'Python' iniciado por Stack, Fevereiro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following dictionary in python:

    d = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'}


    I need a way to find if a value such as "one" or "two" exists in this dictionary.

    For example, if I wanted to know if the index "1" existed I would simply have to type:

    "1" in d


    And then python would tell me if that is true or false, however I need to do that same exact thing except to find if a value exists.

    Continue reading...

Compartilhe esta Página