Blossoms assignment always return false

Hi. My code this code is a Hash map with a linked list (assignment “Blossoms”)

I followed the instructions and watched the video to find the mistake, but the code keeps returning None.

Can any of you see the mistake?

(Spoiler alert, full code for assignment added below)

from linked_list import Node, LinkedList
from blossom_lib import flower_definitions 

class HashMap:
  
  def __init__(self, size):
    self.array_size = size
    self.array = [LinkedList() for i in range(size)]
    
  def hash(self, key):
      return sum(key.encode())
      
  def compress(self, hash_code):
    return hash_code % self.array_size
  
  def assign(self, key, value):
    array_index = self.compress(self.hash(key))
    payload = Node([key, value])
    list_at_array = self.array[array_index]
    
    for item in list_at_array:
      if key == item[0]:
        item[1] = value
        return

      list_at_array.insert(payload)
    
  def retrieve(self, key):
    array_index = self.compress(self.hash(key))
    list_at_index = self.array[array_index]
    for lst in list_at_index:
      if key == lst[0]:
        return lst[1]
      return None
    
blossom = HashMap(len(flower_definitions))
for flower in flower_definitions:
  blossom.assign(flower[0], flower[1])
  
print(blossom.retrieve('hyacinth'))

Hi there.

A link to the project being asked about is usually rather helpful. :slight_smile:

You’ve made an indentation error in your retrieve function. Your for loop will only ever run once, can you see why?

1 Like

Thank you for fast reply :slight_smile:
I thought I got it, but changing the Return None indentation dosen’t change it. I see it needs to be indentet on the level of ‘for’. still returns none.

Hi there.

You have another indentation error in your assign function, again something is inside your for loop which shouldn’t be. :slight_smile:

1 Like

Thank you :pray:
I’ll go through the whole thing again just to make sure :slight_smile: