Regex to return set of words from file that can be spelled with letters passed as parameter (python)
<p>I have a list of words such as </p>

<pre><code>name
age
abhor
apple
ape
</code></pre>

<p>I want to do regex on a list by passing a random set of letters  such as 'apbecd'</p>

<p>Now all those words from the list having the set of letters must be returned.</p>

<p>eg: <code>python retun_words.py apbelcdg</code></p>

<p>will return </p>

<pre><code>ape
apple
age
</code></pre>

<p>As of now, i am able to return words based only on words match. How can I achieve the results as I have mentioned above.
also if there is any other way to achieve the results instead of regex kindly let me know</p>

<p>Thanks in advance</p>

<p>I believe shellmode's method needs a minor fix, since it would not work for cases when the examined letter is the same as the last letter in the word, but the word itself contains letters that are not from the letter list. I believe that this code would work:</p>

<pre><code>import sys
word_list = ['name', 'age', 'abhor', 'apple', 'ape']
letter_list = sys.argv[1]

for word in word_list:
    for counter,letter in enumerate(word):
        if letter not in letter_list:
            break
        if counter == len(word)-1: #reached the end of word
            print word 
</code></pre>

python regex