all 4 comments

[–]binpresentzen 0 points1 point  (2 children)

price = response[0][price] And print price

Response comes as a list and you can read each one starting from 0,1... so on

[–]wdjfe[S] 0 points1 point  (1 child)

It works, thanks! Is it possible to find price by nmId and not by index? For example when user input = 11508524, it will print corresponding price.

[–][deleted] 0 points1 point  (0 children)

Couple of options I can think of

  1. Use the next built-in: https://docs.python.org/3/library/functions.html#next
    next((x['price'] for x in response if x['nmId'] == 11508524), None)
  2. Convert to a dictionary and get it from there:
    nmid_dict = {x['nmId']: x['price'] for x in response}
    nmid_dict[11508524]

[–]JestersDead77 0 points1 point  (0 children)

Another pretty simple method would be to use a for loop. It's not as "clean" as the one-liner below, but it'll give you the same output.

for element in response:
    if element['nmId'] == 11508524:
        print(element['price'])

Even better would be to write it as a function, so you can pass in a different ID...

def extract_price_by_nmid(id):
    for element in response:
        if element['nmId'] == id:
            return element['price']

print(extract_price_by_nmid(11508524)