Can I do a reduce on a list comprehension into two lists, based on two values?
- by pdknsk
I've got the following code.
sum_review = reduce(add,[book['rw'] for book in books])
sum_rating = reduce(add,[book['rg'] for book in books])
items = len(books)
avg_review = sum_review/items
avg_rating = sum_rating/items
What I'd like is this.
sum_review,sum_rating = reduce(add,([book['rw'],[book['rg']) for book in books])
items = len(books)
avg_review = sum_review/items
avg_rating = sum_rating/items
Obviously this doesn't work. How can I solve this redundancy, without a regular loop?