Word guessing game -- Can this be written any better?
<p>This is just a portion of the game, a function that takes in the secret word and the letters guessed as arguments and tells you if they guessed the word correctly.</p>

<p>I'll be completely honest, this is from an assignment on an edX course, <strong>however</strong> I have already passed this assignment, this code works. I am just wondering if it can be written any better. Some people in the discussion forums were talking about how they solved it with 1 line, which is why I'm asking.</p>

<pre class="lang-py prettyprint-override"><code>def isWordGuessed(secretWord, lettersGuessed):
    guessed = []
    l= str(lettersGuessed)
    s= list(secretWord)
    for i in l:
        if i in s:
            guessed.append(i)
            guessed.sort()
            s.sort()
    return guessed == s
</code></pre>

<p>Here is one of the test cases from the grader as an example:</p>

<p><code>isWordGuessed('durian', ['h', 'a', 'c', 'd', 'i', 'm', 'n', 'r', 't', 'u'])</code></p>

<p>Something like this is pretty short:</p>

<pre><code>def isWordGuessed(secretWord, lettersGuessed):
  return all([c in lettersGuessed for c in secretWord])
</code></pre>

<p>For every character in the <code>secretWord</code> ensure it's in the <code>lettersGuessed</code>. This basically creates a list of booleans and the built-in <a href="https://docs.python.org/3/library/functions.html#all" rel="nofollow">all</a> returns <code>True</code> if every element in the array is <code>True</code>.</p>

<p>Also, FWIW: Idiomatic python would use underscores and not camel case.</p>

python python-3.x