Remove Item from Dictionary
Remove Item from Dictionary
Tags: Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a dictionary and a key, and returns a new dictionary with the specified key removed. This problem is designed to help you practice removing items from dictionaries
. The function should accept two parameters and return the updated dictionary.
Constraints:
- The first input will be a
dictionary
. - The second input will be a
key
that exists in the dictionary. - The function should
return
a newdictionary
with the key removed. - Do not modify the original dictionary.
Example:
- Input:
{"name": "John", "age": 30}, "age"
- Output:
{"name": "John"}
Test Case | Input | Expected Output |
---|---|---|
1 | [{"name": "John", "age": 30}, "age"] | {"name": "John"} |
2 | [{"a": 1, "b": 2, "c": 3}, "b"] | {"a": 1, "c": 3} |
3 | [{"key": "value"}, "key"] | {} |
4 | [{"x": 10, "y": 20}, "x"] | {"y": 20} |
5 | [{"list": [1,2], "num": 3}, "list"] | {"num": 3} |
Leave a Comment
Please login to leave a comment.