Skip to content

Update palindrome.py #1509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions other/palindrome.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Program to find whether given string is palindrome or not
def is_palindrome(str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str is a builtin in Python so this usage "shadows" that builtin which is not a good idea. Can you please change all occurrences of str with just plain s?

Also, please change the function signature by adding Python type hints: def is_palindrome(s: str) -> bool: and add similar type hints to the function recursive_palindrome().

Let's add another function:

def slice_palindrome(s: str) -> bool:
    return s == s[::-1]

"""
This function return True is given string is Palindrom other wise return False.

>>> is_palindrome('MALAYALAM')
True
>>> is_palindrome('String')
False
>>> is_palindrome('rotor')
True
>>> is_palindrome('level')
True
>>> is_palindrome('A')
True
>>> is_palindrome('BB')
True
>>> is_palindrome('ABC')
False
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove one of these two blank lines.


start_i = 0
end_i = len(str) - 1
while start_i < end_i:
Expand Down