-
-
Save robsondepaula/750cfa6c4f04295b8e9a469de608d2e4 to your computer and use it in GitHub Desktop.
Instructor code that was shown on screen
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 characters
import sys | |
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