#!/usr/bin/env python
import sys
import re
wgrams = []
buff = open(sys.argv[1]).read()
words = re.findall(r'\w+', buff.lower())
for w in words:
for ww in words:
if w == ww:
continue
if len(w) != len(ww):
continue
test = [c for c in ww]
for c in w:
if c in test:
test.remove(c)
else:
break
if not test:
if w not in wgrams and ww not in wgrams:
wgrams.append(w)
print "%s, %s" % (w,ww)
print "Found %d anagrams!" % len(wgrams)