I want a one line solution In Python the following code, but how?
total = 0 for ob in self.oblist: total+=sum(v.amount for v in ob.anoutherob)
Returns the total value. I want one liner, plz help me
No need to double sum() calls
sum()
total = sum(v.amount for ob in self.oblist for v in ob.anotherob)
You can simply roll the for loop to another level of understanding:
for
total = sum(sum(v.amount for v in ob.anotherob) for ob in self.oblist)