Python/Dictionaries

< Python

Objective

  • Learn about Python dictionaries.
  • Learn about the dictionary's syntax.
  • Learn about built-in dictionary functions.
  • Work with loops using dictionary keys and values.
  • Learn when to use dictionaries and when not to.

Lesson

Python dictionaries are sequences that contains a list of keys, where each key points to a value. Dictionaries act just like real life dictionaries, where the key is the word and the value is the word's definition. Dictionaries use the curly brackets ({}) like the set, however empty curly brackets will create a dictionary over a set.

>>> {"blue": 0, "red": 1, "green": 2}
{'green': 2, 'red': 1, 'blue': 0}
>>> {30: "0", 31: "1", "32": 2}
{'32': 2, 30: '0', 31: '1'}
>>> isinstance({}, dict)
True
>>> isinstance({}, set)
False

Assignments

Completion status: this resource is a stub, which means that pretty much nothing has been done yet.

This article is issued from Wikiversity - version of the Friday, April 17, 2015. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.