Skip to content
Advertisement

Python: How do you remove a dict in a list of dicts of list of dicts? [closed]

as a startingpoint i have this list:

JavaScript

how do you query this list of dicts to remove specific dicts, e.g. when stockQuantity == 0 i want to remove the whole dict, i also want to remove the whole ‘pid’-dict when stocktotal == 0:

JavaScript

do you do this kind of data cleaning before, while or after you write a CSV File of it?

Advertisement

Answer

I went with a dedication function to perform the filters that you want:

  • Filter out any products.product.variantIds where stockQuantity == 0
  • Calculate the products.product.totalquantity and remove the product from the list if 0
JavaScript

If you want to store the result in a csv file, then you certainly need to perform this action before writing it to the file.

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