From the course: Programming Foundations: Real-World Examples

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add items to dictionaries

Add items to dictionaries - Python Tutorial

From the course: Programming Foundations: Real-World Examples

Start my 1-month free trial

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. Five five five, nine seven five four. Now we'll use my simple alphabetical hashing function to figure out where to put this card. Amanda starts with the 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. I have the script start_08_02_rolodex from the exercise files open, which defines my original rolodex. Amanda is not currently in the rolodex dictionary. I'll run the script and switch over to the interactive shell. Now, if I…

Contents