Lets say I have a list letters = ["a", "c", "t"]
, how would I check if those letters could make the word "cat"?
Asked
Active
Viewed 73 times
-4

Hugh Chalmers
- 49
- 1
- 9
-
`guessed_letters.append(letter)` – Patrick Haugh Nov 16 '16 at 21:00
-
Possible duplicate of [append vs. extend](http://stackoverflow.com/questions/252703/append-vs-extend) – Patrick Haugh Nov 16 '16 at 21:01
-
@PeterWood You'd have to sort both sides before comparing. – chepner Nov 16 '16 at 21:10
-
How would I convert the list to be in the order that the word is? So how would I make this list ['c', 'a', 't'] – Hugh Chalmers Nov 16 '16 at 21:12
2 Answers
0
Not sure why your question is drawing so much bad attention. permutations
are what you need:
from itertools import permutations
def is_perm(letters,word):
for p in permutations(letters):
if ''.join(p) == word: return True
return False
letters = ["a", "c", "t"]
word = 'cat'
print is_perm(letters,word)
Letters may of course be any list of strings, not just letters.

kabanus
- 24,623
- 6
- 41
- 74
-
It used to be a different question, but I changed that. However since then it's still been going down. Not sure why, too. Thanks for the help tho. :) – Hugh Chalmers Nov 16 '16 at 21:12
-
2I did not personally downvote, but I believe others may have done so because you did not show that you attempted anything before asking the question. – Elliot Roberts Nov 16 '16 at 21:18
-
-
People should really comment when they downvote, it's polite and helpful. Otherwise you're missing the point of stackexchange, helping (IMO). – kabanus Nov 16 '16 at 21:21
-
1@kabanus people also tend to downvote answers to lazy questions, to discourage users from answering them. I guess this is what happened here. – vaultah Nov 16 '16 at 21:28
-
@HughChalmers if this answers your question you should mark it accepted with the check mark to the left `<------` – Wayne Werner Dec 01 '16 at 14:01
0
This would do the job. It checks to see if all of the letters are in the word, and all of the word letters are in the list.
letters = ['c', 'a', 't']
word = "cat"
def check_word(lst, word):
for letter in lst:
if letter not in word:
return False # "this series does not work"
for letter in list(word):
if letter not in lst:
return False # "this series does not work"
return True # "this works"
check_word(letters, word) # returns True

Jake Conway
- 901
- 16
- 25