Skip to content

Instantly share code, notes, and snippets.

@koushikmln
Created February 6, 2018 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koushikmln/4aecd0c739ca5c75a451fdbf0bcf718d to your computer and use it in GitHub Desktop.
Save koushikmln/4aecd0c739ca5c75a451fdbf0bcf718d to your computer and use it in GitHub Desktop.
from functools import reduce
def getTotalById(order_items,id):
filtered_list = filter(lambda x: int(x.split(",")[1]) == id,order_items)
subtotal = map(lambda x: float(x.split(",")[4]), filtered_list)
return reduce(lambda x,y: x + y,subtotal)
order_items = open("/data/retail_db/order_items/part-00000","r").read().splitlines()
getTotalById(order_items[:20],5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment