Skip to content

Commit

Permalink
Merge pull request #49 from MIT-Emerging-Talent/is_palindrome
Browse files Browse the repository at this point in the history
Is palindrome (second pull request after revert merge)
  • Loading branch information
theabdallahnjr authored Jan 10, 2025
2 parents 0ed1d70 + da3cc37 commit 7787fb6
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 599 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
}
},
"cSpell.words": [
"Alamassi"
]
}
11 changes: 0 additions & 11 deletions solutions/Square_Root_Floor

This file was deleted.

1 change: 1 addition & 0 deletions solutions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

41 changes: 0 additions & 41 deletions solutions/count_consonants.py

This file was deleted.

38 changes: 0 additions & 38 deletions solutions/count_even_numbers.py

This file was deleted.

43 changes: 0 additions & 43 deletions solutions/count_the_number_of_words.py

This file was deleted.

73 changes: 73 additions & 0 deletions solutions/is_palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
A module for checking if a string is a palindrome.
Module contents:
- is_palindrome: checks whether a given string is a palindrome,
ignoring spaces, punctuation, and case differences.
Created on 2024-12-30
@author: Huda Alamassi
"""

import unicodedata


def is_palindrome(text_to_check: str) -> bool:
"""
The function takes in a string and returns True if the string is a palindrome
(reads the same backward as forward ignoring spaces, punctuation,
and case differences) and False otherwise.
Arguments:
text_to_check (str): The input string to be checked.
Returns:
bool:
- True if the string is a palindrome after removing spaces, punctuation,
and case differences.
- False if the string is not a palindrome or contains only spaces/punctuation.
Raises:
AssertionError: If the input is not a string.
Examples:
>>> is_palindrome("radar")
True
>>> is_palindrome("hello")
False
>>> is_palindrome("A man, a plan, a canal, Panama!")
True
>>> is_palindrome("No 'x' in Nixon")
True
"""
# validate input type
assert isinstance(text_to_check, str), "text_to_check must be a string"

# ensure case-insensitivity
text_to_check = text_to_check.lower()

# whitespace should not impact the palindrome check
text_to_check = "".join(text_to_check.split())

# punctuation should not impact the palindrome check
cleaned_text = ""
for text_char in text_to_check:
if not unicodedata.category(text_char).startswith("P"):
cleaned_text += text_char

# exclude empty or non-informative strings
if cleaned_text == "":
return False

reversed_text = cleaned_text[::-1]

return reversed_text == cleaned_text
63 changes: 0 additions & 63 deletions solutions/most_frequent_character.py

This file was deleted.

102 changes: 0 additions & 102 deletions solutions/num_converter.py

This file was deleted.

1 change: 1 addition & 0 deletions solutions/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 7787fb6

Please sign in to comment.