tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,2 @@
|
|||
def is_palindrome(s):
|
||||
return s == s[::-1]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def is_palindrome_r(s):
|
||||
if len(s) <= 1:
|
||||
return True
|
||||
elif s[0] != s[-1]:
|
||||
return False
|
||||
else:
|
||||
return is_palindrome_r(s[1:-1])
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
def is_palindrome_r2(s):
|
||||
return not s or s[0] == s[-1] and is_palindrome_r2(s[1:-1])
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
def test(f, good, bad):
|
||||
assert all(f(x) for x in good)
|
||||
assert not any(f(x) for x in bad)
|
||||
print '%s passed all %d tests' % (f.__name__, len(good)+len(bad))
|
||||
|
||||
pals = ('', 'a', 'aa', 'aba', 'abba')
|
||||
notpals = ('aA', 'abA', 'abxBa', 'abxxBa')
|
||||
for ispal in is_palindrome, is_palindrome_r, is_palindrome_r2:
|
||||
test(ispal, pals, notpals)
|
||||
Loading…
Add table
Add a link
Reference in a new issue