Skip to content

Instantly share code, notes, and snippets.

@matthewrobertbell
Last active December 16, 2015 05:09
Show Gist options
  • Save matthewrobertbell/5382717 to your computer and use it in GitHub Desktop.
Save matthewrobertbell/5382717 to your computer and use it in GitHub Desktop.
Do you even code bro?
import urlparse
import collections
def tree():
return collections.defaultdict(tree)
urls = (l.strip() for l in open('urls.txt') if len(l.strip()))
data = tree()
for url in urls:
parsed = urlparse.urlparse(url)
data[parsed.path][parsed.netloc] = url
for path, urls in data.items():
print path, urls.values()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment