

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Hashmaps
incomplete
2: Hash Function
incomplete
3: Insert
incomplete
4: Get
incomplete
5: Hash Map Review
incomplete
6: Resizing
incomplete
7: Linear Probing
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Let's build a toy hash map in Python. In the real world, you would almost always use the built-in Python dictionary if you need a hash map. However, just using a dictionary doesn't teach us about what's going on under the hood!
As it turns out, the binary search tree was overkill for profile lookups on the LockedIn website. We don't need any of the fancy ordered traversals or range queries after all - and because LockedIn is such a business failure (our CEO's words, not mine) we can store every user in memory, no need to save them to the hard drive.
Let's build a hashmap! We'll use the strings (usernames) as keys, and map them to user objects.
Complete the HashMap's key_to_index method. It should: