vendredi 12 novembre 2021

delete multiple keys from json using Python [duplicate]

I would like to delete all the keys from a JSON file, that contain the words "spotify" and "album". When I execute the following code, it works:

for key in list(data.keys()):
    if "spotify" in key:
        del data[key]

When I add a second word, it returns an empty dict:

for key in list(data.keys()):
    if "spotify" or "album" in key:
        del data[key]

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire