In python, 8. Write a function called doublePalindrome which is passed a string
ID: 3920320 • Letter: I
Question
In python,
8. Write a function called doublePalindrome which is passed a string and returns True if the
string is a "double" palindrome (the same word forward and backwards and every letter appears
twice in a row. Examples: “aabbccbbaa”, “a”, “”, “ccaattaacc”). Otherwise return False.
"""
# Your function goes here - uncomment the next lines
"""
s = "aabbccddccbbaa"
print("Double palindrome %s ? %s" % (s,doublePalindrome(s)))
s = "aabbcbbaa"
print("Double palindrome %s ? %s" % (s,doublePalindrome(s)))
s = "aa"
print("Double Palindrome %s ? %s" % (s,doublePalindrome(s)))
"""
Explanation / Answer
def doublePalindrome(s):
i = 0
j = len(s) -1
while i < j:
if s[i] != s[j]:
return False
i = i + 1
j = j -1
i = 0
while i < len(s) - 1:
if s[i] != s[i+1]:
return False
i = i + 2
return True
print(doublePalindrome("aabbaa"))
print(doublePalindrome("abbaa"))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.