Python Fundamentals

Dictionaries Review

Python Fundamentals

Check out a free preview of the full Python Fundamentals course

The "Dictionaries Review" Lesson is part of the full, Python Fundamentals course featured in this preview video. Here's what you'd learn in this lesson:

Nina reviews what was covered in the previous sections.

Preview
Close

Transcript from the "Dictionaries Review" Lesson

[00:00:00]
>> Nina Zakharenko: Feel like your minds are spinning, you know where this is going. Okay, so going back to our dictionary cheat sheet, the use here it's used for storing data in key value pairs. The keys used must be immutable data types. If they're not you're gonna get an error.

[00:00:17]
For creation just two, empty curly braces or calling dict for an empty dictionary, or for a dictionary with items in it. The key on the left side, a colon separating a key value pair, followed by the value and a comma, and then as many other key value pairs as you want.

[00:00:41]
Makes sense, right? Kind of almost sort of like a set, but with an extra addition of also putting in the value. Search methods is key in my dict, that is very fast. So, one in numbs, very fast, especially kind of for larger data structures. Some common methods and dictionaries using the key parsed into the square brackets to get back the value of the item.

[00:01:18]
My dict.items for all key value pairs. My dict.key is for all the key. And my dict.values for all the values. Okay, now is the order preserved? Sort of, as of Python 36, a dictionary is sorted in insertion order. So, like with a set there was just no order at all.

[00:01:42]
But now, in a new version of Python, the dictionary knows kind of when things were put into it in what order. But those items that can't be accessed by index, they can only be accessed by key. So, kind of sort of a little bit different than the other data types we saw.

[00:02:01]
Is the dictionary mutable? Yes, we can add and remove items to it. Is the dictionary in place sortable? No, it's not.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now