Skip to content

Instantly share code, notes, and snippets.



Created Apr 16, 2013
What would you like to do?
Thumbtack PyCon 2013 challenge
#!/usr/bin/env python
import collections
import itertools
import re
import sys
words = {
for word in re.split(r'\W+',
if len(word) >= 4
pairs = collections.defaultdict(list)
where = collections.defaultdict(set)
for a, b in itertools.combinations(words, 2):
key = ''.join(sorted(a + b))
if key not in where[a] and key not in where[b]:
pairs[key].append((a, b))
max_len = 0
for key in pairs:
if len(pairs[key]) > max_len:
max_len = len(pairs[key])
print max_len
for key in pairs:
if len(pairs[key]) == max_len:
print pairs[key]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment