Western Governors University (WGU) ICSC2100 C949 Data Structures and Algorithms I Practice Exam

Session length

1 / 20

Dictionary keys must be _____ and ______.

mutable, duplicate

unique, mutable

unique, immutable

In Python, dictionary keys must be unique and immutable. This means that no two keys in the same dictionary can have the same value, which is essential for maintaining the integrity of key-value pairs within the dictionary. Immutability is crucial because mutable objects, like lists or dictionaries themselves, can change and thus cannot reliably serve as keys. If keys could be mutable, it would create confusion, as changing a key would alter its identity, leading to unexpected behavior when trying to retrieve or modify values associated with that key.

The uniqueness requirement ensures that each key corresponds to exactly one value. When you attempt to add a new key-value pair with an existing key, it will simply update the value associated with that key instead of adding a new entry. This is key to how dictionaries efficiently manage and retrieve data.

Understanding these characteristics of dictionary keys is fundamental to effectively using dictionaries in Python for data storage and management.

Get further explanation with Examzify DeepDiveBeta

case-sensitive, string

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy