Blossom Hash Map Project

I’ve completed the Blossom Hash Map Project but when I ask it to print the meaning of rose, I get None. I watched the video and did exactly what the programmer suggested. I think there is something not right with the assign method.

def assign(self, key, value):
array_index = self.compressor(self.hash(key))
payload = Node([key,value])
list_at_array = self.array[array_index]
for item in list_at_array:
if item[0] == key:
item[1] = value
return
list_at_array.insert(payload)

I don’t see how the Nodes get into the self.array?

Thanks
Marie

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

1 Like

Could you edit or re-post your code but formatted for the forums along with a link to the project, the following FAQ has some useful advice on this front. Without the formatting, especially indentation, it is very hard to read your code.

1 Like

Thanks

‘’’
def assign(self, key, value):
array_index = self.compressor(self.hash(key))
payload = Node([key,value])
list_at_array = self.array[array_index]
for item in list_at_array:
if item[0] == key:
item[1] = value
return
list_at_array.insert(payload)
‘’’

Ah, I see where I went wrong. The indentation in the retrieve method was incorrect. it works now. but I still don’t understand how self.array gets updated when we are only updating a local variable to the assign method (list_at_array)

2 Likes

Ah, sorted it out anyway. Nice one. That’s a local identifier but it refers to the same object as self.array[array_index] since you make that assignment a few lines above.

This isn’t a copy of that list; it’s the same list, so when you change it both names still refer to the same updated object. If that’s something new to you then it’s worth looking up how Python deals with names, objects and mutable data types. It takes a little getting your head around at first but a lot of things start to make more sense afterwards.

Thanks for your help!

1 Like