How to select words of equal max length from a text document
<p>I am trying to write a program to read a text document and output the longest word in the document. If there are multiple longest words (i.e., all of equal length) then I need to output them all in the same order in which they occur. For example, if the longest words were dog and cat your code should produce:</p>

<p>dog cat</p>

<p>I am having trouble finding out how to select numerous words of equal max length and print them. This is as far as I've gotten, I am just struggling to think of how to select all words with equal max length:</p>

<p>open the file for reading</p>

<pre><code>fh = open('poem.txt', 'r')

longestlist = []  
longestword = ''  

for line in fh:
    words = (line.strip().split(' '))  
    for word in words:  
        word = ''.join(c for c in word if c.isalpha())  
        if len(word) &gt; (longestword):  
            longest.append(word)

for i in longestlist:  
    print i  
</code></pre>