FAQ: Hash Maps: Python - Review


#1

This community-built FAQ covers the “Review” exercise from the lesson “Hash Maps: Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

Complex Data Structures

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Hello!

I was just copying down the code in my notes and found something that I don’t understand.

def retrieve(self, key):
array_index = self.compressor(self.hash(key))
possible_return_value = self.array[array_index]

if possible_return_value is None:
  return None

if possible_return_value[0] == key:
  return possible_return_value[1]

retrieval_collisions = 1

while (possible_return_value != key):
  new_hash_code = self.hash(key, retrieval_collisions)
  retrieving_array_index = self.compressor(new_hash_code)
  possible_return_value = self.array[retrieving_array_index]

  if possible_return_value is None:
    return None

  if possible_return_value[0] == key:
    return possible_return_value[1]

  number_collisions += 1

return

This is the retrieval method but it ends with += 1 for number_collisions and not retrieval_collisions. This is the solution that Codecademy gives, so I think it must be right, only I don’t understand why we +1 number_collisions which is in the Assign method. Can anyone explain? Thanks!


#3

i think so it’s a typo, the correct solution would be retrieval_collisions+=1