Skip to content

Instantly share code, notes, and snippets.

@eevmanu
Last active February 1, 2023 16:37
Show Gist options
  • Save eevmanu/9e12161c2b8152837e8b3e30cc3a1f3e to your computer and use it in GitHub Desktop.
Save eevmanu/9e12161c2b8152837e8b3e30cc3a1f3e to your computer and use it in GitHub Desktop.
age counting solution in python
# import requests
# r = requests.get("coderbyte.com/api/challenges/json/age-counting")
# d = r.json()
d = {
"data": "key=IAfpK, age=58, key=WNVdi, age=64, key=jp9zt, age=47, key=0Sr4C, age=68, key=CGEqo, age=76, ... key=cFCfU, age=5, key=J8an1, age=48, key=dkSlj, age=5"
}
l = d['data'].split(", ")
# https://stackoverflow.com/q/5389507
def pairwise(iterable):
a = iter(iterable)
return zip(a, a)
d2 = {}
for key, age in pairwise(l):
d2[key.split("=")[1]] = int(age.split("=")[1])
# change this to whatever number is useful
THRESHOLD = 0
count = 0
for key, age in d2.items():
if age >= THRESHOLD:
count += 1
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment