I'm facing a problem that I don't really understand. Please take a look at the given code, where the two relevant variables have the following form:
jsd = {"data": {"User": .....}}
lists = [{"genre": "XY", "meanScore": Float},..., {"genre": "XY", "meanScore": Float}]
The code is:
jsd = json.loads(r.text)
lists = jsd["data"]["User"]["stats"]["favouredGenresOverview"]
for k, entry in enumerate(lists):
if entry["meanScore"] == None:
del(lists[k])
The goal is to remove all the dict
's in lists
where the key meanScore
is equal to None
. The problem is that for some reason the loop only runs over half of lists
... I think I've read somewhere on the site that when trying to remove something from a dict
one should use pop
, but I honestly wasn't able to figure out how to that or if it even was relevant to my question (As far as I understand I'm removing list elements).
Can someone maybe help?