Skip to content

Instantly share code, notes, and snippets.

@Makistos
Last active December 15, 2016 08:10
Show Gist options
  • Save Makistos/0bb9ca00ea6e819e77a3742d983499c3 to your computer and use it in GitHub Desktop.
Save Makistos/0bb9ca00ea6e819e77a3742d983499c3 to your computer and use it in GitHub Desktop.
Given a word, check which lines of text in a file contain all the letters in that word. Takes two parameters: file name with the lines of text and the letters to search. #python #hidden-word #list-comprehension
# Slurp file into list
with open(sys.argv[1]) as f:
names = f.read().splitlines()
to_search = sys.argv[2].lower()
answer = [x for x in names if all(True if to_search.count(item) <= x.lower().count(item) else False for item in set(to_search))]
print answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment