solutions

Search keys for value

Write a function that receives a dictionary and a value to search for as input. Return a set with all the keys from the dictionary that have that value.

search_keys_for_value({"name" : "Billy", "age" : 12, "fav_num" : 12}, 12)

# {"age", "fav_num"}

Test Cases

test search for number - Run Test

def test_search_for_number():
    a_dict = {
        "name": "billy",
        "age": 12,
        "fav_num": 12
    }
    assert search_keys_for_value(a_dict, 12) == {'fav_num', 'age'}

test search for word - Run Test

def test_search_for_word():
    a_dict = {
        1: "hi",
        2: "there",
        3: "easter egg"
    }
    assert search_keys_for_value(a_dict, "easter egg") == {3}

test search not found - Run Test

def test_search_not_found():
    a_dict = {
        "a": "i",
        "b": "love",
        "c": "programming"
    }
    assert search_keys_for_value(a_dict, "howdy") == set()