Skip to content
Advertisement

Filter Json Keys that contains certain character in Python

I need to filter all Keys in this dict (book-1, book-2 and book-3) that conatains the string ‘book’and save them in a new dict. In this example no need to seave ‘bicycle’.

JavaScript

Advertisement

Answer

This can be accomplished with a dict comprehension, which can be updated based on your needed filter:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement