- Prof. Dancy's Site - Course Site -

Priority Queues and Palindromes

Now that you've worked on a function to test palindromes, we're going to use more queues (and a priority queue) to find and hold all the palindromes in a file full of tweets

The task

Your job is to use your code to create a function called find_palindrome. Functionality:

Function header

def find_palindrome(file_name):

    '''
    Function to find all palindromes in a file (for word of length > 2)
    '''
    start = time.clock()

    #Create a queue to hold all the lines in a file
    #Create a priority queue to hold all the words from that file that are palindromes, where the priority is specified by the length of the palindome.
    #use the test_palindrome function to test whether a word is a palindrome
    #close the file and return the time it took to run the function

Function to test how long my solution takes

def test_run_time(n=10, file_name='bucknell_tweets.txt'):
    count = 0
    time_total = 0

    while count < n:
        time_total += find_palindrome(file_name)
        count += 1

    print(time_total/n)