Search code examples
pythonpython-3.xdictionarypython-collections

How to access elements in a dict_values?


I have a dict :

{49: {'created_at': '2018-11-07T13:25:12.000Z', 'url': 'https://www.test.com'}}

I would like to get 'created_at'.

I've attempt through different methods but without a success... I thought this approach would works:

result = di.values()[0] but I get a TypeError: 'dict_values' object does not support indexing

But it doesn't.


Solution

  • You should use: di[49]['created_at']

    or:

    list(di.values())[0]['created_at']