Home > front end >  Can I get the list item in dict?
Can I get the list item in dict?

Time:10-14

There is a list has a dict in it and I need one particular item from the dict look

[{'id': 666197885, 'price': '1.1170', 'qty': '20.0', 'quoteQty': '22.3400', 'time': 1634148815292, 'isBuyerMaker': False}]

I just need time from this list in normally I would use list_name["time"] but this time it gives errors. I couldn't find answer for that and than I realize this thing is not a list its a dict so how can I get the time item from this dict?

CodePudding user response:

You need to access the dictionary within list_name first and then access the value by key name from the dictionary, in this case by taking the first element list_name[0]["time"]

If you expect the list to grow in size, you can pull out all the times with a simple list comprehension: times = [i["time"] for i in list_names]

  • Related