Найти - Пользователи
Полная версия: unhashable type: 'dict'
Начало » Центр помощи » unhashable type: 'dict'
1
BabrieQ
Всем привет!

Есть задание: на полках лежат документы, пользователь по команде хх может удалить полку, если она пустая.

 def remove_shelf(number):
    if number in [directories]:
        if len(directories[number]) > 0:
          return 'На полке есть документы, удалите их перед удалением полки. Текущий перечень полок: ' + ', '.join(directories.keys())
        del directories[number]
        print('Полка удалена. Текущий перечень полок: ' + ', '.join(directories.keys()))
    print ('Такой полки не существует. Текущий перечень полок:' + ', '.join(directories.keys()))
remove_shelf(directories)

На строке
  if len(directories[number]) > 0:
выдаёт ошибку unhashable type: ‘dict’

Уже умаялась…
py.user.next
  
>>> d = {'a': 1, 'b': 2}
>>> d[{}]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
>>>

У тебя и функция неправильно написана, и подаётся в неё неправильное значение.
Master_Sergius
Логическая ошибка вот здесь (попробуйте понять какая именно):
 if number in [directories]:
и вот здесь:
 remove_shelf(directories)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB