QuestenaՎարժանք, որը ցույց է տալիս՝ ինչ կրկնել հաջորդիվ
Հարց 37

Why can a list not be used as a key in a Python dictionary?

  1. Lists are unhashable, while dictionary keys must be hashable.Ճիշտ պատասխան
  2. Lists are too large to fit in a dictionary entry.
  3. Only strings may be dictionary keys.
  4. A list would create several duplicate keys automatically.

Բացատրություն

Dictionary keys must be hashable, while a list can change its contents and is unhashable. Allowing arbitrary mutable keys would undermine stable lookup, and a dictionary cannot hold simultaneous duplicate equal keys.

Շարունակեք այս թեստով

Սկսել վարժանքը
Հարց 37: Why can a list not be used as a key in a Python dictionary? · Python Fundamentals · Questena