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>There's no need to use regex. Following code works.</p>

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

for word in word_list:
    for letter in word:
        if letter not in letter_list:
            break
        elif letter == word[-1]:
            print word
</code></pre>

<p>Output </p>

<pre><code>[root@mbp:~]# python return_words.py apbelcdg
age
apple
ape
</code></pre>

python regex