Skip to content
Advertisement

Remove all elements of a string list in python if they contain a given phrase

Have a list called summary containing a corresponding JSON object similar to:

JavaScript

Essentially, if "tables_data": "" is found within the string of a list item, I want the entire list item to be removed.

How would I go about doing this?

Advertisement

Answer

You can do a dictionary-comprehension selecting the dictionary item with 'tables_data' has a value not equals '':

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