1

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.

martineau
  • 119,623
  • 25
  • 170
  • 301
Grégoire de Kermel
  • 434
  • 2
  • 8
  • 22
  • 1
    `result = di['49']['created_at']` – lefloxy Apr 08 '20 at 17:01
  • Does this answer your question? [Get: TypeError: 'dict\_values' object does not support indexing when using python 3.2.3](https://stackoverflow.com/questions/17431638/get-typeerror-dict-values-object-does-not-support-indexing-when-using-python) – Josh Clark Apr 08 '20 at 17:05
  • @Gregoire check Josh's post, you need to cast the d1.values() to a list before accessing element 0 – andreis11 Apr 08 '20 at 17:12
  • Why the downvote? I have this question too. It's relevantly worded such that it brought me here. I wanted to now how to access these `dict_values/dict_keys` w/o having constantly cast to a list; how to use these objs natively? It's not discussed. – Mote Zart Jun 25 '22 at 19:48

2 Answers2

3

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

or:

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

Gabio
  • 9,126
  • 3
  • 12
  • 32
0

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'])
Semih
  • 158
  • 2
  • 13