Skip to content

Instantly share code, notes, and snippets.

@sanoops
Created March 10, 2014 18:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sanoops/9471084 to your computer and use it in GitHub Desktop.
Save sanoops/9471084 to your computer and use it in GitHub Desktop.
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