Implementation of Palindrome check from the words of the file
Verified
Added on 2022/12/26
|7
|531
|1
AI Summary
This document provides the implementation of a Palindrome check from the words of a file. It includes the pseudocode and code for the program, as well as an explanation of how to determine if a word is a Palindrome or not.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Running head: ITECH1400 FUNDAMENTALS OF PROGRAMMING ITECH1400 Fundamentals of Programming Name of the Student Name of the University Authors note
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
1ITECH1400 FUNDAMENTALS OF PROGRAMMING Implementation of Palindrome check from the words of the file Pseudocode Step 1: Read file Step 2: Read all the words or strings in the file. Step 3: Initialize len variable to zero and a flag= zero Step 4: While word[len] is not NULL len++ Initialize “k” to zero , l to len-1 While k < (len/2)+1 If word[i] =word[J] flag=0 else Flag=1 Increment i , l Decrement If flag=0 Print Palindrome else Print Not Palindrome Stop
2ITECH1400 FUNDAMENTALS OF PROGRAMMING Code with open('English.txt') as text: count=0 for line in text: line = line.strip() lines = line[::-1] if line == lines: count+=1 print ('Following line in the text file is a Palindrome!') print(count) print(line)
3ITECH1400 FUNDAMENTALS OF PROGRAMMING Implementation of Palindrome check from the words of the file Pseudocode for the program Get all the strings in a list Remove the spaces and convert to lowercase Read next line as String2. Remove the spaces in between and convert all in lowercase STEP 1: Get one by one letter of the consecutive strings and compare those letters of the next string For the previous word and compare with the first character of next word] STEP 2: count the number of similar words among the two words. [if string.i[1] = string.j[i]
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
4ITECH1400 FUNDAMENTALS OF PROGRAMMING add 1 to total string.i[i] go to next character of the previous string] STEP 3: check for all character/letters. 7[if total length of string= length(string1) then return anagram=true else anagram check =false] OUTPUT: returns true or false for check. Code def bd_dic(path): adict = {} f = open(path, "r") for line in f.readlines(): line = line.strip() key = sort_li(line) if key in adict: v = adict.get(key) + "," + line
5ITECH1400 FUNDAMENTALS OF PROGRAMMING adict[key] = v else: adict[key] = line return adict def sort_li(line): chars = [c for c in line] chars.sort() return "".join(chars) def anagr(adict, line): key = sort_li(line) values = adict.get(key, "NONE") return values.split(",") adict = bd_dic(r"English.txt") results = anagr(adict, "noid") print("Anagrams for [noid]")
6ITECH1400 FUNDAMENTALS OF PROGRAMMING print(results) Screenshot Following is the screen shot of the executed program.