Skip to content

Instantly share code, notes, and snippets.

@nooperpudd
Created August 22, 2017 09:25
Show Gist options
  • Save nooperpudd/4051471dffaf8634f0d3d958c3443fdc to your computer and use it in GitHub Desktop.
Save nooperpudd/4051471dffaf8634f0d3d958c3443fdc to your computer and use it in GitHub Desktop.
Sort domain
def sort_by_domain(sites):
sitebits = [site.lower().lstrip('http://').split('.') for site in sites]
for site in sitebits:
site.reverse()
print(sitebits)
return [('.'.join(reversed(site))) for site in sorted(sitebits)]
@nooperpudd
Copy link
Author

nooperpudd commented Aug 22, 2017

input:

['http://mail.google.com', 'http://reader.google.com',
'http://mail.yahoo.co.uk', 'http://google.com',
'http://mail.yahoo.com']

result:

['http://google.com', 'http://mail.google.com',
'http://reader.google.com', 'http://mail.yahoo.com',
'http://mail.yahoo.co.uk']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment