Questions
Conceptual
- Dictionaries in Python can have duplicate keys. (T/F)
- Dictionaries in Python can be nested, meaning a dictionary can contain another dictionary as a value. (T/F)
[]is tolists as ___ is todicts.
Basic Syntax
Create a new dictionary called
my_dictionarywithstrkeys andfloatvalues and initialize it as an empty dictionary.Using the following dictionary,
msg: dict[str, int] = {"Hello": 1, "Yall": 2}, access the value stored under key “Yall”.Using the following dictionary,
msg: dict[str, int] = {"Hello": 1, "Yall": 2}, increase the value stored under key “Yall” by 3.Using the following dictionary,
ids: dict[int, str] = {100: "Alyssa", 200: "Carmine"}, remove the value “Alyssa”, stored at key 100.Using the following dictionary,
ids: dict[int, str] = {100: "Alyssa", 200: "Carmine"}, write a line of code to get the number of key/value pairs in the dictionary.Using the following dictionary,
stock: dict[str, int] = {"carrots": 50, "beets": 20, "apples": 10}, write a line of code to check if key “carrots” is in the dictionary.
Answers
Conceptul Questions
- False
- True
{}
Syntax Solutions
my_dictionary: dict[str, float] = {}ormy_dictionary: dict[str, float] = dict()msg["Yall"]msg["Yall"] += 3ormsg["Yall"] = 5ids.pop(100)len(ids)carrots in stock