0

I'm having a problem in processing lists that I have 2 lists: shop1= [{'status':'1','price':;1200'},{'status':'1','price':'13000'}] shop2= [{'status':'2','price':3000'},{'status':'2','price':'4000'}]

How can I return the sum of all the prices of shop1, shop2, so?

Baubau
  • 11
  • 1

1 Answers1

-1

For calculating dynamic number of shops input you can use itertools with zip_longest method. Hence you don't need to worry if the items length are not same.

import itertools
shop_items = itertools.zip_longest(shop1, shop2)
total = sum([sum(item["price"] for item in items if item)  for items in shop_items])
ramadnsyh
  • 9
  • 1