Python >>> TypeError: unhashable type: 'list' -


i getting above mentioned error below code, need rectify it.

code:

def in_range_func(self, curtemp, keys):     if keys == []:         return (curtemp, false)     k in keys:         if (k-2) <= curtemp <= (k+2):             return (k, true)       return (curtemp, false)  def sort_func(self):     in self.data:         if in self.temp_dict.keys():             self.temp_dict[i].append(i)         else:             (x, success) = self.in_range_func(i, self.temp_dict.keys())             if success:                 self.temp_dict[i].append(i)             else:                 self.temp_dict[i] = [i]      x in self.temp_dict.keys():         print x, self.temp_dict[x] 

in above code

data = [[1], [4], [34], [45.5], [70.7], [70.9]] temp_dict = {}  

you trying use lists keys; each element in self.data nested list integer in it.

you have 2 options:

  • convert list tuple:

    self.temp_dict[tuple(i)].append(i) 
  • if list ever contains 1 element, use 1 element key:

    self.temp_dict[i[0]].append(i) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -