blossom_lib.py

```
flower_definitions = [['begonia', 'cautiousness'], ['chrysanthemum', 'cheerfulness'], ['carnation', 'memories'], ['daisy', 'innocence'], ['hyacinth', 'playfulness'], ['lavender', 'devotion'], ['magnolia', 'dignity'], ['morning glory', 'unrequited love'], ['periwinkle', 'new friendship'], ['poppy', 'rest'], ['rose', 'love'], ['snapdragon', 'grace'], ['sunflower', 'longevity'], ['wisteria', 'good luck']]
```

linked_list.py

```
class Node:
def __init__(self, value):
self.value = value
def get_value(self):
return self.value
def get_next_node(self):
return self.next_node
def set_next_node(self, next_node):
self.next_node = next_node
class LinkedList:
def __init__(self, head_node=None):
self.head_node = head_node
def insert(self, new_node):
current_node = self.head_node
if not current_node:
self.head_node = new_node
while(current_node):
next_node = current_node.get_next_node()
if not next_node:
current_node.set_next_node(new_node)
def __iter__(self):
current_node = self.head_node
while(current_node):
yield current_node.get_value()
```

script.py

```
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(self.array_size)]
def hash(self, key):
hash_code = sum(key.encode())
return hash_code
def compress(self, hash_code):
return hash_code % self.array_size
def assign(self, key, value):
hash_code = self.hash(key)
array_index = self.compress(hash_code)
payload = Node([key, value])
list_at_array = self.array[array_index]
for node in list_at_array:
if node[0] == key:
node[1] = value
return
list_at_array.insert(payload)
def retrieve(self, key):
hash_code = self.hash(key)
array_index = self.compress(hash_code)
list_at_index = self.array[array_index]
print(key)
for node in list_at_index:
if node[0] == key:
print(node[0], node[1])
return node[1]
return None
blossom = HashMap(len(flower_definitions))
for flower in flower_definitions:
blossom.assign(flower[0], flower[1])
print(blossom.retrieve('daisy'))
print(blossom.retrieve('begonia'))
```

In Computer Science Path, this code (script.py is written by me, and code academy provided with linked_list.py and blossom_lib.py) belongs to project: âBlossomâ in Complex Data Structures, Learn HashMap.

Here, you can see my code(script.py), I am confused why it is not working?

I tried to debug it, and found that linked_list.py have an **iter** method. I did some research and found that its a generator method, since it uses âyieldâ. I think there is a problem somewhere in it, since it is not iterating correctly. I found that it should have a **next** method too. Please someone suggest what is wrong here? Am I right about **next** method, if so, then how to implement it? Or my code (script.py) have some problem?