Python dictionaries are similar to lists. Where a list uses a number to keep track of the individual elements contained within it, a dictionary (generally) uses a word.


Create an empty dictionary (see adding below to add items to an empty dictionary)

person = { }

Creating a dictionary with initial data

person = {"givenName" : "Paul", "familyName" : "Baumgarten"}

Getting elements from the dictionary

print( person["givenName"] )
print( person["familyName"] )

Adding / modifying elements in the dictionary

person["email"] = "pbaumgarten@isl.ch"
person["website"] = "https://pbaumgarten.com"

Remove an element from the dictionary

del person["website"]

Loop through all the elements of the dictionary

for key,val in person.items():
  print("field "+key+" has value "+val)