sand
sand

Reputation: 115

python3x TypeError: 'dict_keys'

This line of code generates dict_keys error:

Line:657    lr = LEARNING_RATE[LEARNING_RATE.keys()[0]]

error log:

  File "/home/dan/AcousticEventDetection-master/AED_train.py", line 657, in <module>
    lr = LEARNING_RATE[LEARNING_RATE.keys()[0]]
TypeError: 'dict_keys' object does not support indexing

How to fix this error, please?

original code from: https://github.com/kahst/AcousticEventDetection/blob/692535d6a282d0a356770c262f67347cdb56ece7/AED_train.py

Upvotes: 0

Views: 377

Answers (1)

Francesco
Francesco

Reputation: 977

That's because keys() will give you a view, not a list. Views are like set, they are unordered, so you can't index them. Check the docs here.

Upvotes: 1

Related Questions