- Prof. Dancy's Site - Course Site -
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
Your job is to use your code to create a function called find_palindrome
.
Functionality:
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
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)