mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-03 06:01:55 -04:00
Add some cool queue, stacks, strings, math, bit manipulation examples (#35)
This commit is contained in:
parent
f3ee2cdf52
commit
0f455a0322
24 changed files with 932 additions and 13 deletions
arrays_and_strings
23
arrays_and_strings/palindrome.py
Normal file
23
arrays_and_strings/palindrome.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
def is_palindrome(sentence):
|
||||
|
||||
sentence = sentence.strip(' ')
|
||||
if len(sentence) < 2:
|
||||
return True
|
||||
|
||||
if sentence[0] == sentence[-1]:
|
||||
return is_palindrome(sentence[1:-1])
|
||||
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Testing is_palindrome()...')
|
||||
sentence ="subi no onibus"
|
||||
print(f'Is {sentence} a palindrone?: {is_palindrome(sentence)}')
|
||||
|
||||
sentence ="helllo there"
|
||||
print(f'Is {sentence} a palindrone?: {is_palindrome(sentence)}')
|
Loading…
Add table
Add a link
Reference in a new issue