Bug
##Bug
WhetherWhether we use [::-1]
or reversed()
to reverse the input string, we have a bug when the input contains characters that are formed using combining accents, as demonstrated by these additional tests:
##Bug
Whether we use [::-1]
or reversed()
to reverse the input string, we have a bug when the input contains characters that are formed using combining accents, as demonstrated by these additional tests:
Bug
Whether we use [::-1]
or reversed()
to reverse the input string, we have a bug when the input contains characters that are formed using combining accents, as demonstrated by these additional tests:
def is_palindrome(x):
'''
True if the letters of x are the same when
reversed, ignoring differences of case.
>>> is_palindrome('')
True
>>> is_palindrome('a')
True
>>> is_palindrome('a0')
False
>>> is_palindrome('ab')
False
>>> is_palindrome('ab a')
False
>>> is_palindrome('Aba')
True
>>> is_palindrome('Àbà')
True
'''
x = x.lower()
# Alternative (letters only):
# x = ''.join(filter(str.isalpha, x.lower()))
# Alternative (letters and digits only):
# x = ''.join(filter(str.isalnum x.lower()))
return x[::-1] == x
if __name__ == '__main__':
import sys
for string in sys.argv[1:]:
# check each command-line argument
message = 'is a palindrome' if is_palindrome(string) else 'is not a palindrome'
print(f'{string} {message}')
else:
# no arguments, so run serfself-test
import doctest
doctest.testmod()
True
>>> is_palindrome("o̅o") # o+overline, o
False
>>> is_palindrome("o̅o̅") # o+overline, o+overline
True
def is_palindrome(x):
'''
True if the letters of x are the same when
reversed, ignoring differences of case.
>>> is_palindrome('')
True
>>> is_palindrome('a')
True
>>> is_palindrome('a0')
False
>>> is_palindrome('ab')
False
>>> is_palindrome('ab a')
False
>>> is_palindrome('Aba')
True
>>> is_palindrome('Àbà')
True
'''
x = x.lower()
# Alternative (letters only):
# x = ''.join(filter(str.isalpha, x.lower()))
# Alternative (letters and digits only):
# x = ''.join(filter(str.isalnum x.lower()))
return x[::-1] == x
if __name__ == '__main__':
import sys
for string in sys.argv[1:]:
# check each command-line argument
message = 'is a palindrome' if is_palindrome(string) else 'is not a palindrome'
print(f'{string} {message}')
else:
# no arguments, so run serf-test
import doctest
doctest.testmod()
True
>>> is_palindrome("o̅o") # o+overline, o
False
>>> is_palindrome("o̅o̅") # o+overline, o+overline
True
def is_palindrome(x):
'''
True if the letters of x are the same when
reversed, ignoring differences of case.
>>> is_palindrome('')
True
>>> is_palindrome('a')
True
>>> is_palindrome('a0')
False
>>> is_palindrome('ab')
False
>>> is_palindrome('ab a')
False
>>> is_palindrome('Aba')
True
>>> is_palindrome('Àbà')
True
'''
x = x.lower()
# Alternative (letters only):
# x = ''.join(filter(str.isalpha, x.lower()))
# Alternative (letters and digits only):
# x = ''.join(filter(str.isalnum x.lower()))
return x[::-1] == x
if __name__ == '__main__':
import sys
for string in sys.argv[1:]:
# check each command-line argument
message = 'is a palindrome' if is_palindrome(string) else 'is not a palindrome'
print(f'{string} {message}')
else:
# no arguments, so run self-test
import doctest
doctest.testmod()
>>> is_palindrome("o̅o") # o+overline, o
False
>>> is_palindrome("o̅o̅") # o+overline, o+overline
True
- 87.8k
- 14
- 104
- 325
Usage of thisthese optional arguments should be apparent from the extra tests I've added.
We##Bug
Whether we use [::-1]
or reversed()
to reverse the input string, we have a bug withwhen the input contains characters that are formed using combining accents, as demonstrated by these additional tests:
Usage of this should be apparent from the extra tests.
We have a bug with characters that are formed using combining accents, as demonstrated by these additional tests:
Usage of these optional arguments should be apparent from the extra tests I've added.
##Bug
Whether we use [::-1]
or reversed()
to reverse the input string, we have a bug when the input contains characters that are formed using combining accents, as demonstrated by these additional tests:
- 87.8k
- 14
- 104
- 325
- 87.8k
- 14
- 104
- 325
- 87.8k
- 14
- 104
- 325