SHARE
TWEET

Untitled

a guest Jun 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [
  2.     {
  3.         "id": 1,
  4.         "name": "Bulbasaur",
  5.         "type": [
  6.             "grass",
  7.             "poison"
  8.         ]
  9.     },
  10.     {
  11.         "id": 2,
  12.         "name": "Ivysaur",
  13.         "type": [
  14.             "grass",
  15.             "poison"
  16.         ]
  17.     }
  18. ]
  19.      
  20. ["Bulbasaur","Ivysaur"]
  21.      
  22. import json
  23. try:
  24.     with open("./simple.json", 'r') as f:
  25.         contents = json.load(f)
  26. except Exception as e:
  27.     print(e)
  28.  
  29. print(contents[:]["name"])
  30.      
  31. contents = [
  32.     {
  33.         "id": 1,
  34.         "name": "Bulbasaur",
  35.         "type": [
  36.             "grass",
  37.             "poison"
  38.         ]
  39.     },
  40.     {
  41.         "id": 2,
  42.         "name": "Ivysaur",
  43.         "type": [
  44.             "grass",
  45.             "poison"
  46.         ]
  47.     }
  48. ]
  49.  
  50. li = []
  51. for item in contents:
  52.     li.append(item.get('name'))
  53.      
  54. print([d["name"] for d in contents])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top