Anagrams

Find anagrams with Python

#!/usr/bin/env python3
from collections import Counter
import sys,os
s=sys.argv[1]
def anagrams(word,words):
    cw=Counter(word)
    return [w for w in words if Counter(w)==cw]
base=os.path.dirname(os.path.abspath(__file__))
path=os.path.join(base,"words.txt")
with open(path) as f:
    lines=f.read().splitlines()
print(anagrams(s,lines))

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment