-1

So I have a list like the following

[{'id': '290910533794791424', 'invite': 'KEY', 'orderid': 'YMHBK8', 'order': 'specified value'}]

How would I obtain a certain value such as the orderid?

jpp
  • 159,742
  • 34
  • 281
  • 339
Nat L
  • 7
  • 4
  • 2
    `my_data[0]['orderid']`. You have a dictionary that's wrapped in a list. If you want to be able to access it without that `[0]`, do `my_data = my_data[0]`, and then you can just use `my_data['orderid']`. – Engineero Apr 27 '18 at 21:16

1 Answers1

0

You have a list containing a single dictionary.

Therefore, you can retrieve the value for a given key by either extracting the first element explicitly or iterating the list once:

lst = [{'id': '290910533794791424', 'invite': 'KEY',
        'orderid': 'YMHBK8', 'order': 'specified value'}]

res = next(iter(lst))['orderid']  # 'YMHBK8'
res = lst[0]['orderid']           # 'YMHBK8'
jpp
  • 159,742
  • 34
  • 281
  • 339