Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active November 11, 2018 05:38
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 toyeiei/e49d1f95ebfe0c28e8f1fc1f6ed63ba6 to your computer and use it in GitHub Desktop.
Save toyeiei/e49d1f95ebfe0c28e8f1fc1f6ed63ba6 to your computer and use it in GitHub Desktop.
Case Study - US Births Analysis Function
# write function for this analysis
def calculate_stat(data, k, v):
"""
input: data, idx key, idx value
output: dictionary with key: value pair
"""
result = {}
for row in data:
key = row.split(",")[k]
value = int(row.split(",")[v])
if key in result:
result[key] += value
else:
result[key] = value
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment