Blossom project type error

Dear all,

Why do I get a type error: ‘list’ object cannot be interpreted as an integer with the following code:

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 number 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])

    #self.array[array_index] = [key, value]

    list_at_array = self.array[array_index]

    for node in list_at_array:

      if node.value[0] == key:

        node.value[1] = value

    list_at_array.insert(payload)

    

  def retrieve(self, key):

    array_index = self.compress(self.hash(key)) 

    list_at_index = self.array[array_index]

    for node in list_at_index:

      if node.value[0] == key:

        return node.value[1]

      else:

        return None  

    if payload[0] == key:

      return payload[1]

    elif payload[0] == None or payload[0]  !=key:

      return None

blossom = HashMap(flower_definitions)

Hi,

What’s the line number and snippet of your error? (python tells you).

In terms of interpreting the error, get used to inspecting the object that triggered the error and considering: do I need to make an adjustment to this object, or was the way this object was procured inaccurate (given the new information)?

The error comes from one trying to do an operation that is reserved for integers with lists (arrays) instead.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.