Created
June 29, 2020 23:56
-
-
Save rlopez0689/ef443144da03480368bbce5794b6f5aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
orders = [ | |
{ | |
'order_id': 98348, | |
'title': 'A Moon Shaped Pool', | |
'quantity': 4, | |
'price': 40 | |
}, | |
{ | |
'order_id': 8439834, | |
'title': 'In Rainbows', | |
'quantity': 10, | |
'price': 30 | |
}, | |
{ | |
'order_id': 98348934, | |
'title': 'Kid A', | |
'quantity': 8, | |
'price': 45 | |
}, | |
{ | |
'order_id': 902384, | |
'title': 'Ok Computer', | |
'quantity': 20, | |
'price': 60 | |
} | |
] | |
orders_computed = list(map(lambda item: (item['order_id'], item['quantity'] * item['price']), orders)) | |
orders_filtered = list(filter(lambda item: item[1] >= 300, orders_computed )) | |
total = reduce(lambda x, y: x + y[1], orders_filtered, 0) | |
total = reduce(lambda x, y: x + y[1], filter(lambda item: item[1] >= 300, map(lambda item: (item['order_id'], item['quantity'] * item['price']), orders) ), 0) | |
print(total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment