Created
March 10, 2014 18:25
-
-
Save sanoops/9471084 to your computer and use it in GitHub Desktop.
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.0 | |
oldKey = None | |
dummy_Data=["Miami 12.34","Miami 99.07","Miami 55.07","NYC 88.97","NYC 33.56"] | |
for line in dummy_Data: | |
data = line.strip().split(" ") | |
if len(data) != 2: | |
# Something has gone wrong. Skip this line. | |
continue | |
thisKey, thisSale = data | |
if oldKey and oldKey != thisKey: | |
print oldKey, ":", salesTotal | |
oldKey = thisKey | |
salesTotal = 0 | |
oldKey = thisKey | |
salesTotal += float(thisSale) | |
if oldKey != None: | |
print oldKey, ":", salesTotal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment