Skip to content

Instantly share code, notes, and snippets.

@AndreaCatalucci
Last active August 29, 2015 13:56
Show Gist options
  • Save AndreaCatalucci/9230615 to your computer and use it in GitHub Desktop.
Save AndreaCatalucci/9230615 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import sys
for line in sys.stdin:
data = line.strip().split("\t")
if len(data) != 6:
continue
date, time, store, item, cost, payment = data
print "{0}\t{1}".format(store, cost)
#! /usr/bin/env python
import sys
for line in sys.stdin:
data = line.strip().split("\t")
if len(data) != 6:
continue
date, time, store, item, cost, payment = data
print "{0}\t{1}".format(store, cost)
#! /usr/bin/env python
import sys
sales_total = 0
old_key = None
for line in sys.stdin:
data = line.strip().split("\t")
if len(data) != 2:
continue
key, sales = data
if (old_key and key != old_key):
print "{0}\t{1}".format(old_key, sales_total)
sales_total = 0
old_key = key
sales_total += float(sales)
print "{0}\t{1}".format(old_key, sales_total)
#! /usr/bin/env python
import sys
max_cost = 0
old_key = None
for line in sys.stdin:
data = line.strip().split("\t")
if len(data) != 2:
continue
store, cost = data
if (old_key and key != old_key):
print "{0}\t{1}".format(old_key, sales_total)
max_cost = 0
old_key = key
max_cost = max(cost, max_cost)
print "{0}\t{1}".format(old_key, max_cost)
#! /usr/bin/env python
import sys
sales_total = 0
sales_num = 0
old_key = None
for line in sys.stdin:
data = line.strip().split("\t")
if len(data) != 2:
continue
key, sales = data
if (old_key and key != old_key):
print "{0}\t{1}".format(old_key, sales_total)
sales_total = 0
old_key = key
sales_total += float(sales)
sales_num += 1
print "{0}\t{1}\t{1}".format(old_key, sales_total, sales_num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment