In this part, you'll write a function full_reverse
which performs a slightly more sophisticated ordering reversal strategy than before.
For example, if I call full_reverse(['ab', 'cd'])
, I should get back a list that contains ['dc', 'ba']
, whereby both the two elements have been flipped in the list, and the letters in each string have also been reversed.
You cannot use the built-in reverse
method. Sorry!
In [ ]:
In [ ]:
try:
full_reverse
except:
assert False
else:
assert True
In [ ]:
i1 = ['ab', 'cd']
a1 = set(['dc', 'ba'])
assert a1 == set(full_reverse(i1))
i2 = ["race", "car"]
a2 = set(["rac", "ecar"])
assert a2 == set(full_reverse(i2))
In [ ]:
assert set([]) == set(full_reverse([]))
assert set(["a"]) == set(full_reverse(["a"]))
assert set(["abcde"]) == set(full_reverse(["edcba"]))
In this question, you'll use your solution from Part A to write a function named is_full_palindrome
.
True
or False
This function should return True
if the input list is a full palindrome--this means that, after you've performed the full_reverse
function on an input, the output from that function should be identical to the original input.
For example, is_full_palindrome(["racecar", "abcba", "racecar"])
should return True
, but is_full_palindrome(["racecar", "abcab", "noxinnixon"])
should return False
(because when the order of the list itself is reversed, the elements no longer line up with the original, even though the individual elements are themselves palindromes).
You can potentially do this problem without using your answer from Part A, but that would be a more difficult route, since you'd probably end duplicating your code from Part A anyway.
Hint: Empty lists and single-letter strings are considered palindromes!
In [ ]:
In [ ]:
try:
is_full_palindrome
except:
assert False
else:
assert True
In [ ]:
i1 = ["racecar", "abcba", "racecar"]
assert is_full_palindrome(i1)
i2 = ["racecar", "abcab", "noxinnixon"]
assert not is_full_palindrome(i2)
i3 = ["not", "even", "close"]
assert not is_full_palindrome(i3)
In [ ]:
assert is_full_palindrome([])
assert is_full_palindrome(["a"])
assert is_full_palindrome(["b", "c", "b"])
assert not is_full_palindrome(["a", "b", "c", "e", "b", "a"])