From the course: Programming Concepts for Python
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Add items to dictionaries - Python Tutorial
From the course: Programming Concepts for Python
Add items to dictionaries
- A moment ago, I wanted to call Amanda to invite her over, but when I went to look up her phone number in my Rolodex, it wasn't there. I guess I never added it. Fortunately, Olivia has Amanda's phone number. - Here you go. - Thanks. Now I need to add a new card to my Rolodex for Amanda. I'll take a new Rolodex card and write Amanda's name on the top, and then her phone number on the bottom. 555-9754. Now I'll use my simple alphabetical hashing function to figure out where to put this card. Amanda starts with a letter A, so that's her index, and I'll store her card in the A section. Next time I need to look up Amanda's number, I can just flip to the A's and find it right away. Adding Amanda to the Python Rolodex is just as easy as adding a new card to the physical Rolodex. To demonstrate that we'll be using the same Python Rolodex as before, which I've already loaded into a new Python session using an import statement…