[python] Pull the value of a specific key from json to make it a list

Asked 2 weeks ago, Updated 2 weeks ago, 0 views


When the above file is referred to as example.json, I would like to make a list by extracting only the values for key'A'. How can I code in this case? (For example, I didn't write down the path name correctly, but the actual file contains all the data values correctly.)

with open('example.json') as make_json:
       json_data = json.load(make_json)

I read it like this A_value = json_data["A"] causes a TypeError that the index in the list must be integrers, not str.

I'd appreciate your help.

python json

2022-09-20 16:21

1 Answers

A_values = [ e["A"] for e in json_data ]
To do so


2022-09-20 16:21

If you have any answers or tips

© 2022 pinfo. All rights reserved.