Skip to content

Instantly share code, notes, and snippets.

@Makistos
Created July 14, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Makistos/06128c66e72456dd6339 to your computer and use it in GitHub Desktop.
Save Makistos/06128c66e72456dd6339 to your computer and use it in GitHub Desktop.
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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment