Skip to main content

Dictionaries versus Lists

Dictionaries are similar to lists, but there are a few differences:

Both dictionaries and lists:

  • are used to organize elements into collections;

  • are used to initialize a new dictionary or list, use empty brackets;

  • can iterate through the items or elements in the collection; and

  • can use a variety of methods and operations to create and change the collections, like removing and inserting items or elements.

Dictionaries only:

  • are unordered sets;

  • have keys that can be a variety of data types, including strings, integers, floats, tuples;.

  • can access dictionary values by keys;

  • use square brackets inside curly brackets { [ ] };

  • use colons between the key and the value(s);

  • use commas to separate each key group and each value within a key group;

  • make it quicker and easier for a Python interpreter to find specific elements, as compared to a list.