Access Dictionary Item
Access Dictionary Item
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 the value associated with the key. This problem is designed to help you practice accessing values in dictionaries
. The function should accept two parameters and return the value corresponding to the key.
Constraints:
- The first input will be a
dictionary
. - The second input will be a
key
that exists in the dictionary. - The function should
return
the value associated with the key.
Example:
- Input:
{"name": "John", "age": 30}, "age"
- Output:
30
Test Case | Input | Expected Output |
---|---|---|
1 | [{"name": "John", "age": 30}, "age"] | 30 |
2 | [{"a": 1, "b": 2, "c": 3}, "b"] | 2 |
3 | [{"x": 10, "y": 20}, "x"] | 10 |
4 | [{"key1": "value1", "key2": "value2"}, "key2"] | "value2" |
5 | [{"bool": True, "list": [1, 2, 3]}, "bool"] | True |
Leave a Comment
Please login to leave a comment.