Makistos
7/14/2015 - 7:09 PM

This "oneliner" finds all words that can be created from the characters in the word given as a parameter. The list to match against in this

This "oneliner" finds all words that can be created from the characters in the word given as a parameter. The list to match against in this example is a list of official Finnish words. #python #kotus #hidden_words

#!/usr/bin/python

# Create text list from Kotus list with
# sed -ne 's,.*<s>\(.*\)</s>.*,\1,p' kotus-sanalista_v1/kotus-sanalista_v1.xml > kotus_sanat.txt
#
# Kotus is an "official" list of Finnish words found from http://kaino.kotus.fi/sanat/nykysuomi/.
# 
# This "oneliner" finds all words that can be created from the characters in the
# word given as a parameter.

import sys

with open('kotus_sanat.txt') as f:
  words = f.read().splitlines()

answer = set([x for x in words if all(True if x.count(item) <= sys.argv[1].count(item) else False for item in x)])

print 'Words: ' + str(len(answer))
print ', '.join(sorted(list(answer)))