Skip to content

Instantly share code, notes, and snippets.

@rlopez0689
Created June 29, 2020 23:56
Show Gist options
  • Save rlopez0689/ef443144da03480368bbce5794b6f5aa to your computer and use it in GitHub Desktop.
Save rlopez0689/ef443144da03480368bbce5794b6f5aa to your computer and use it in GitHub Desktop.
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