Question: Write a function palindrome _ re ( n ) that takes a number n and returns a regular expression that matches strings that are palindromes

Write a functionpalindrome_re(n)that takes a numbernand returns a regular expression that matches strings that are palindromes of length n. Your regular expression can use whatever capturing groups you like---we'll only be checking whether or not it matches, not what it captures.
>>> r = palindrome_re(5)
>>> bool(re.fullmatch(r, 'abcba'))
True
>>> bool(re.fullmatch(r, 'abcbd'))
False
>>> bool(re.fullmatch(r, 'eeeee'))
True
>>> bool(re.fullmatch(r, 'racecar'))
False
>>> bool(re.fullmatch(r,'#..#'))
True create a function such that it checks the first character of string is same as the last , second character as second last, third as third last and so on to check if its palindrome

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!