With everything in our setter taken care of, we want to make sure that when we retrieve our value we’re retrieving the correct value.



In .retrieve() if possible_return_value has a different key than the one we’re looking for, we should continue searching.

Define a new variable called retrieval_collisions and set it equal to 1.


Insert a new while loop that checks if

possible_return_value[0] != key

In the while loop, we want to replicate our retrieval logic while increasing the count of retrieval_collisions so that we continue to look at other locations within our array.

Call .hash() with both the key and retrieval_collisions. Save that result into new_hash_code.


Plug new_hash_code into .compressor(). Save that result into retrieving_array_index.


Check self.array at retrieving_array_index and save the result as possible_return_value. Check against the three possibilities:

  • If it’s None, return None
  • If it has a value, but a different key, increment retrieval_collisions.
  • If it’s key matches our key return possible_return_value[1].

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?