Skip to content

Instantly share code, notes, and snippets.

@lucasp90
Created September 9, 2018 14:33
Show Gist options
  • Save lucasp90/bd11d8d558f89c9a81d29e63e6787b06 to your computer and use it in GitHub Desktop.
Save lucasp90/bd11d8d558f89c9a81d29e63e6787b06 to your computer and use it in GitHub Desktop.
Coding challenges
def get_subdomains(domain):
tokens = domain.split('.')
subdomains = []
for i in range(len(tokens)):
subdomains.append(".".join(tokens[i:]))
return subdomains
def main():
results = {}
visits_data = [ "900,google.com",
"60,mail.yahoo.com",
"10,mobile.sports.yahoo.com",
"40,sports.yahoo.com",
"300,yahoo.com",
"10,stackoverflow.com",
"2,en.wikipedia.org",
"1,es.wikipedia.org" ]
visits_data = map(lambda v: v.split(','), visits_data)
for visits, domain in visits_data:
subdomains = get_subdomains(domain)
for subdomain in subdomains:
results[subdomain] = results.get(subdomain, 0) + int(visits)
print(results)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment