- 16th Jul 2024
- 18:13 pm
- Adan Salman
In this assignment you will be given a file called RandomWords.txt. The file contains a list of words, one word in each line. Your task is to look at each word in the RandomWords.txt and see if the word read backwards is also a word in the RandomWords.txt file. If the word is, save the word in the list. After went through each of the word, sort the list in alphabetical order, print out/write the word paired with its read-backwards word to the file called Target.txt. Be mindful that the Target.txt file should only have one pair of the words, no duplicates, for example, Step--Pets and Pets--Step are considered the same, so you only need one of the pair appearing in the Target.txt file.
Identifying Palindromic Word Pairs from RandomWords.txt - Get Assignment Solution
Please note that this is a sample assignment solved by our Python Programmers. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- Option 1 - To download the complete solution along with Code, Report and screenshots - Please visit our Programming Assignment Sample Solution page
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial solution for this assignment in this blog below
Free Assignment Solution - Identifying Palindromic Word Pairs from RandomWords.txt
try:
word_list = []
unique_list = []
file_name = input("Enter file name to be read: ")
file=open(file_name, "r")
lines = file.readlines()
for word in lines:
word = word.replace("\n", "")
word_list.append(word)
file.close()
for i in range(0, len(word_list)):
word = word_list[i]
for j in range(i+1, len(word_list)):
w = word_list[j]
w = w[::-1]
if word.lower() == w.lower():
if word not in unique_list:
unique_list.append(word)
unique_list.sort()
file = open('Target.txt', 'w')
for word in unique_list:
reverse_word = word
reverse_word = reverse_word[::-1]
reverse_word = reverse_word.title()
file.write(word + " -- "+ reverse_word+"\n")
file.close()
print("Data written to Target.txt")
except:
print("Could not read the file")
Get the best Identifying Palindromic Word Pairs from RandomWords.txt assignment help and tutoring services from our experts now!
About The Author - Alexa Joey
Alexa Joey specializes in Python programming with a focus on data manipulation and algorithmic challenges. With expertise in file handling, text processing, and algorithm design, Alexa excels in solving complex programming tasks. Her skills extend to creating efficient scripts for data analysis and manipulation, ensuring robust and effective solutions.