We'll load in the data via;
import json
import pathlib
poke_dict = json.loads(pathlib.Path("pokemon.json").read_text())
Next well define a new class called Clumper
. The idea is that this
class will allow us to more flexibly analyse the list of json objects for us.
class Clumper:
def __init__(self, blob):
self.blob = blob
def keep(self, func):
return [d for d in self.blob if func(d)]
You can see how it works by running.
Clumper(poke_dict).keep(lambda d: 'Grass' in d['type'])
Can you see a downside with this current approach though?