Skip to content

Instantly share code, notes, and snippets.

@muntasir2165
Forked from chenghan/gist:7456549
Created May 26, 2014 22:40
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 muntasir2165/9596d892696f4678e873 to your computer and use it in GitHub Desktop.
Save muntasir2165/9596d892696f4678e873 to your computer and use it in GitHub Desktop.
salesTotal = 0
oldKey = None
for line in sys.stdin:
data = line.strip().split("\t")
if len(data) != 2:
# Something has gone wrong. Skip this line.
continue
thisKey, thisSale = data
if oldKey and oldKey != thisKey:
print oldKey, "\t", salesTotal
oldKey = thisKey;
salesTotal = 0
oldKey = thisKey
salesTotal += float(thisSale)
if oldKey != None:
print oldKey, "\t", salesTotal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment