B
B
become_iron2015-04-07 15:54:09
Python
become_iron, 2015-04-07 15:54:09

What is "Unhashable type"?

I tried to do one thing with the dictionary - such a thing came out. But that's not the point. What is the essence of this concept? Esteemed, those are lists and dictionaries. I would like a little theory in an accessible language
Well, actually the code, where it manifested itself
TypeError: unhashable type: 'list'

audio = [
{'lyrics_id': 3586866, 'title': 'Fruhling in Paris', 'id': 358450897, 'artist': 'Rammstein', 'owner_id': 358450897},
{'lyrics_id': 3655472, 'title': 'Zwitter', 'id': 358450894, 'artist': 'Rammstein', 'owner_id': 358450897}
]
keys_to_delete = ['owner_id', 'duration', 'url', 'lyrics_id', 'album_id', 'genre_id']
for i in range(len(audio)):
    for j in range(len(keys_to_delete)):
        if audio[i].get([keys_to_delete[j]]):  # есть ли такой ключ в словаре
            del(audio[i][keys_to_delete[j]])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Yakovenko, 2015-04-07
@become_iron

if audio[i].get(keys_to_delete[j]):
It seems that you are passing a list to where an unmutable value should be passed, that is, a key from your keys_to_detele list.
Notice I removed the square brackets around keys_to_delete[j]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question