79462319

Date: 2025-02-24 02:15:52
Score: 1
Natty:
Report link

As @mavix mentioned in a comment to another post:

In python3, dict.keys() returns a 'dict_keys' object instead of a list, which does not support indexing Blockquote

One solution to this would be converting that object into a list by iterating through it. It's not the most elegant solution and shouldn't really be used if can be avoided.

first_key = [key for key in prices.keys()][0]
#           ^Converts keys into a list    ^Takes the first key from the list
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @mavix
  • Low reputation (0.5):
Posted by: Lev Slinsen