using fibonacci sequence to print out words
<p>I am writing a program where it prints out how the frequency of a word as long as the frequency is in the fibonacci sequence (1,2,3,5,8,etc). I have figured out how to print all the words that appear once, however I am having trouble figuring out how to iterate so it prints out the words that have a higher freqeuncy.</p>

<pre><code>import string
import itertools

def fib():
    a,b = 0, 1
    while 1:
        yield b
        a, b = b, a + b

while True:
    filename = raw_input('Enter a file name: ')
    if filename == 'exit':
        break
    try:
        file = open(filename, 'r') 
        text = file.read() 
        file.close() 
    except:
        print('file does not exist')
    else:

        for word in string.punctuation:
            text=text.replace(word, "")
        word_list = text.lower().split(None)
        word_freq = {}

        for word in word_list:
            if len(word) &gt; 1:
                word_freq[word] = word_freq.get(word, 0) + 1

        frequencies = sorted(word_freq.items(), key=lambda item: item[1])
        a = fib()
        order = sorted(word_freq.values())
        n = 1
        a = next(a)
        for words in frequencies:
            try:
                if a == words.index(n):
                    print(words)
            except:
                print('nope')  # HELP: how would I iterate here??


print('Bye')
</code></pre>
