find all words in list/file that begin/ends with a specific prefix/suffix
<p>The below code gives the words which begin/ends with a specific prefix/suffix.</p>

<pre><code>string_list = [line.strip() for line in open("file.txt", 'r')]
for word in string_list:
    if word[-1] == "a":
        print word


string_list = [line.strip() for line in open("file.txt", 'r')]
for word in string_list:
    if word[0] == "fi":
        print word
</code></pre>

<p>How can i optimize it to be real fast on huge data.
also how can i pass the param like</p>

<pre><code>python test.py --prefix fi
python test.py --suffix o
</code></pre>

<p>Thanks in advance.</p>

<p>If you need speed, you could simply use <a href="https://en.wikipedia.org/wiki/Grep" rel="nofollow">GREP</a>, which is written in a lowlevel language and is bound to be faster than a python loop by leaps and bounds. </p>

<p>It is also portable and runs just fine on Linux/Windows/OSX/...</p>

python regex prefix suffix