You can’t use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like append() and extend().
It is best to think of a dictionary as a set of key: value pairs, with the requirement that the keys are unique (within one dictionary). A pair of braces creates an empty dictionary: {}. Placing a comma-separated list of key:value pairs within the braces adds initial key:value pairs to the dictionary; this is also the way dictionaries are written on output.
The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair with del. If you store using a key that is already in use, the old value associated with that key is forgotten. It is an error to extract a value using a non-existent key.
Performing list(d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it sorted, just use sorted(d) instead). To check whether a single key is in the dictionary, use the in keyword.
In questa pagina del sito puoi guardare il video online Python quick Tips: Why You Can't Use a List as a Dictionary Key della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Bytes & Beyond 22 giugno 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 29 volte e gli è piaciuto 0 spettatori. Buona visione!