solutions

Add Python to Dict

Write a function that receives a dictionary as input, adds a new key-value pair saying "fav_language": "python" to it, and returns it! :D

add_to_dictionary({"first_name": "jon", "last_name": "snow"})

# {
#   "first_name": "jon",
#   "last_name": "snow",
#   "fav_language": "python"
# }

Test Cases

test overwrite existing key - Run Test

def test_overwrite_existing_key():
    assert add_to_dictionary({
        "fav_language": "elvish"
    }) == {
        "fav_language": "python"
    }

test add new key to dictioanry - Run Test

def test_add_new_key_to_dictioanry():
    original = {
        "first_name": "jon",
        "last_name": "snow"
    }
    expected = {
        "first_name": "jon",
        "last_name": "snow",
        "fav_language": "python"
    }
    assert add_to_dictionary(original) == expected