Last active
February 5, 2022 20:17
Revisions
-
chenghan revised this gist
Jun 10, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ import sys salesTotal = 0 oldKey = None @@ -10,7 +12,7 @@ thisKey, thisSale = data if oldKey and oldKey != thisKey: print oldKey, "\t", salesTotal oldKey = thisKey salesTotal = 0 oldKey = thisKey -
chenghan created this gist
Nov 13, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ 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