Python Language Dictionary: Difference between revisions
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
* [[Python_Language#Dictionary|Python Language]] | * [[Python_Language#Dictionary|Python Language]] | ||
=Overview= | =Overview= | ||
A dictionary is a mutable collection of key-value pairs. The pairs can be [[#Access_a_Dictionary|accessed]] and [[#Modify_a_Dictionary|modified]]. | A dictionary is a mutable collection of key-value pairs. The pairs can be [[#Access_a_Dictionary|accessed]] and [[#Modify_a_Dictionary|modified]]. Each key is unique within the key set, and can be an instance of any immutable type: boolean, integer, float, tuple, string, etc. In other programming languages, the same data structure is referred to as "[[Bash_Arrays#Associative_Arrays|associative array]]" or "[[Hash_Table#Overview|hash tables]]" or "hash maps". | ||
=Create a Dictionary= | =Create a Dictionary= |
Revision as of 19:51, 16 February 2022
Internal
Overview
A dictionary is a mutable collection of key-value pairs. The pairs can be accessed and modified. Each key is unique within the key set, and can be an instance of any immutable type: boolean, integer, float, tuple, string, etc. In other programming languages, the same data structure is referred to as "associative array" or "hash tables" or "hash maps".
Create a Dictionary
Empty map
m = {}
Access a Dictionary
Access Individual Elements
[]
, get()
An attempt to access an inexistent key ends up in a KeyError
exception being thrown.
Test the existence of a key.
Access:
d["key"]
Get All Keys
Get All Values
Modify a Dictionary
Modify Individual Elements
Add, modify, delete.