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.

Upvotes: 1

Views: 7542

Answers (2)

Semih
Semih

Reputation: 165

You may use dict items for it.

dic = {49: {'created_at': '2018-11-07T13:25:12.000Z', 'url': 'https://www.test.com'}}
for j,k in dic.items():
     print(k['created_at'])

Upvotes: 1

Gabio
Gabio

Reputation: 9494

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

or:

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

Upvotes: 3

Related Questions