Using regex match any 5 palindrome from the txt file q4txt A

Using regex, match any 5 palindrome from the .txt file: q4.txt

Answer should be in red:
catac
xyzyx
PoloP
12321

q4.txt:
abcde
catac
xyzyx
PoloP
fadsfas
afasdfafa
abccataccba
12321
theoneabovework

Solution

Answer

#file data

\"\"\"

abcde

catac

xyzyx

PoloP

fadsfas

afasdfafa

abccataccba

12321

\"\"\"

import regex

#method for palindrome

def palindrome(filename):

    #open file

    #E:/qt4.txt

    newfile= open(filename,\'r\')

    filedata = newfile.readlines();

    #iterate the filedata

    for each in filedata:

        #using regex module

        if(regex.search(r\"(\\w)((?R)|(\\W?))\\1\",each) is             None):

            palindromeword = each

            print(palindromeword)

filename = input(\"Enter file name \")

          

palindrome(filename)

  

Using regex, match any 5 palindrome from the .txt file: q4.txt Answer should be in red: catac xyzyx PoloP 12321 q4.txt: abcde catac xyzyx PoloP fadsfas afasdfaf
Using regex, match any 5 palindrome from the .txt file: q4.txt Answer should be in red: catac xyzyx PoloP 12321 q4.txt: abcde catac xyzyx PoloP fadsfas afasdfaf

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site