0

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

sand
  • 105
  • 1
  • 1
  • 5
  • possible duplicate of : https://stackoverflow.com/questions/18552001/accessing-dict-keys-element-by-index-in-python3 – yodebu May 08 '20 at 12:56

1 Answers1

1

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.

Francesco
  • 897
  • 8
  • 22
  • kindly, if I want to re-write the above line, how it should be? – sand May 08 '20 at 13:12
  • `lr = LEARNING_RATE[list(LEARNING_RATE)[0]]`, check also [this](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) for complete undesrtanding – Francesco May 08 '20 at 13:17