Python 3 Programming Tutorial - Dictionaries
Key Takeaways
This video tutorial covers the basics of Python dictionaries, including creating, referencing, and modifying dictionaries, as well as using them to store and retrieve data.
Full Transcript
What's going on everybody? Welcome to yet another Python 3 basics tutorial video. In this video, we're going to be talking about dictionaries. So, dictionaries are kind of they're really Python specific, but they're a lot like associative arrays and other languages. Um, and the idea of them is they're an unordered unordered unordered assortment of data. And the data is always keys and values. And again, it's unordered. So, you might enter it in an order and then you might expect an order out of it. Or maybe you want to order your dictionary. You you can kind of hacky order a dictionary, but not really. There is no order inherently to a dictionary. So anyway, again, the idea of a dictionary is to have keys and values. A key will be a single element. Values can be anything. It can be lists, it could be lists within lists, multi-dimensional lists. Your values can be functions, which can get exciting fast. Uh it can be anything. So anyway, uh with that, you can even reference another dictionary in a dictionary. So yeah, uh let's go ahead and show some examples. So we're going to say x dict equals. And to notify Python that you're going to create a dictionary, you use curly braces. And then within the curly braces, let's say we have a a collection of people and their ages. So we're going to say we got Jack. He's 15 years old. We have ourselves a Bob who is 22. We have ourselves an Alice who is she's 12. And then we finally have a Kevin. And Kevin is 17 years old. Okay. So, we have this example dick. Now, just for quick uh kicks, print example dicty reads it. As you can see, it's almost an exact print out of exactly what we just typed. Easy enough. Now, what if we want to reference something in this dictionary? We want to ask this dictionary, hey, how old is Jack? Example, dick. Well, you go print eggs dict. [Music] So, this should be kind of familiar to you guys as far as uh lists are concerned. We're kind of referencing a bit of data. And so Jack is the key and then the value is this number right here. So hopefully it's going to tell us 15. Sure enough it does. Now uh the next thing that we're going to do is so we found out how old Jack is. That's cool. We can reference this. How do we let's say we want to add something to this list. So for example, let's say we want to add Tim. So to do that we'll say exact xdict Tim. So this is basically exactly how we referenced Jack, right? We said xdictked Jack. Just print out that that value. Now we're saying xdict Tim, which doesn't exist already, but we're about to make it exist. He's 14. Okay, so now we can print eggs dicty ears. Sorry, guys. And then we have Tim. Okay, so see how it kind of just added Tim like almost like randomly into this. Um, so yeah, keep that in mind. It's there's no order really to it, but anyway, it added Tim. Now, let's say uh Tim just turned 15 years old, big five. So, now we're going to say example dict Tim equals 15. So, as you can see, we already defined Tim here, and now we're like redefining Tim. Um, and so you'll see this is why dictionaries have to have unique keys. Otherwise, it everything would fall apart. The sky would literally fall. Whoops. We need to print Tim again. Uh, so example dick Timals 15. Look how it uh this this time this time it put Tim second. This time it puts Tim all the way at the end. Wow, crazy stuff. Anyway, Tim's 15. Then we'll print example dict. And we can see at first Tim was 14. Now Tim is 15. Fancy that. Sadly, however, Tim has died. We need to remove him from this list. He's no use being in this list anymore. He's dead. So now, how do we get rid of this Tim guy? Well, let's make some space here. Now, to get rid of something, we can just do dell de example dict Tim. This is going to remove the key and value or values to Tim. Um, whoops. We got to let's print it out after deleting Tim. X dict. So, he was here. Great. 14. Turn 15. Good for him. Then he died. Bummer. Now he's dead. Done. So, um, now just as a quick aside, so this is our list. Let me get rid of all this now. And let's say instead, or not instead, but now, not only are we tracking age, but we're going to track hair color. So Jack, he's 15, and his hair color is blonde. Bob is 22. And Bob's hair color is uh What color is Bob's hair? Brown. I heard brown from the crowd. Now, Alice, Alice is 12 years old, but Alice's hair is black. And we're running out of space, but here's Kevin. Kevin's a ginger, so he's got red head. Sorry if I offended anybody. Um, there we go. Good. Now, we can print. Let's do print example dict uh Jack. Oh, okay. My Spidey sense was tingling that I did something and I sure did. Python 27 coming out of me. Anyway, 15 and blonde. Okay, correct. And we can even go like this. We can say, well, we want to reference just his hair color. Boom. Blonde. Nice. Okay, so this list could go forever if you wanted. You could also create other dictionaries and you could say Jack is equal to another dictionary. You can create functions and say Jack is equal to a function. Um, you can do all kinds of stuff. We'll probably expand on that a little bit more once I get through all of the kind of basic things I want to get through with Python uh 3. Uh, then we'll get into some more in-depth kind of hacky things, some more intermediate things, that kind of stuff. Uh, so anyways, if you guys have any questions or comments, feel free to leave those below. Also, I'm still kind of making this series. Probably some of you first viewers to the series. Um, I'll still be generating this Python 3 series. If you have any requests or anything you definitely want to see, I highly suggest you request them. Uh, that way they show up for you guys. Um, but anyway, someone's at the door. So, I'm going to conclude this video here. If you guys have any questions or comments, leave them below. As always, thanks for watching. Thanks for all the support subscriptions and until next
Original Description
In this Python 3 programming tutorial, we cover Python dictionaries. Dictionaries are a data structure in Python that are very similar to associative arrays. They are unordered and contain "keys" and "values." Each key is unique and the values can be just about anything.
Dictionaries are sets and they are defined with {} curly braces.
Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/
Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex
Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
🎓
Tutor Explanation
DeepCamp AI