Skip to content

Instantly share code, notes, and snippets.

@koushikmln
Created February 6, 2018 09:55
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/50d452c12e762e6a63a7ca8530ee3fd5 to your computer and use it in GitHub Desktop.
Save koushikmln/50d452c12e762e6a63a7ca8530ee3fd5 to your computer and use it in GitHub Desktop.
import itertools as it, sys
from functools import reduce
order_items = open("/data/retail_db/order_items/part-00000","r").read().splitlines()[:50]
order_subtotal = list(map(lambda x: (int(x.split(",")[1]),float(x.split(",")[4])),order_items))
#sorted values should be passed in groupby
iterator = it.groupby(sorted(order_subtotal),lambda x: x[0])
revenuePerOrder = map(lambda x: (x[0], reduce(lambda a,b: a + b, map(lambda v: v[1], x[1]))), iterator)
print(list(revenuePerOrder))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment