Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #save this file as "palindrome.py"
- #will be used as library of functions
- #Returns true if sentence is a palindrome
- def palindrome(sentence):
- count = 0
- sentence = sentence.lower()
- for i in range(len(sentence)):
- if sentence[i] == sentence[-(i+1)]:
- count = count + 1
- return count == len(sentence)
- #takes a string as an input,
- #removes punctuation and spaces and puts all words into a single word
- def one_word(sentence):
- punctuation = [",", "?", ".", " "]
- for i in range(len(punctuation)):
- sentence = sentence.replace(punctuation[i], " ")
- sentence = sentence.split(" ")
- new_sentence = ""
- for i in range(len(sentence)):
- new_sentence = new_sentence + sentence[i]
- return new_sentence
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement