Created
June 26, 2021 12:44
-
-
Save amingilani/0536278e306db3eff0072b381d17dd4e to your computer and use it in GitHub Desktop.
Function that takes in a string of words and returns the subset of palindromes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isolate_palindromes(words: str) -> str: | |
"""Takes in a string of words and returns the subset of palindromes | |
Args: | |
words (str): string of words, e.g. "bar kaak" | |
Returns: | |
str: any palindromes within the string of words passed, e.g. "kaak" | |
""" | |
return [word for word in words.split() if word == word[::-1]] | |
# Replace the value of this contant with the one you want to use | |
WORDS = "ballot kayak rat racecar hellcat" | |
print(isolate_palindromes(WORDS)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment