I am trying to make my function locate duplicate words and if so the output should be True or False depending on wether there are duplicate words. For example:
doubleWord("cat") --> False .
doubleWord("catcat") --> True .
doubleWord("contour" * 2) --> True
So far I have this:
def main():
word = input("Enter a string: ")
half = len(word) >> 1
if word[:half] == word[half:]:
print("True")
else:
print("False")
return
print(main())
if name == "main": main()
Any help would be greatly appreciated. I thought maybe using slicing would make it easier but I have no idea how to implement that in my code. Thanks!
You just have to compare the first part with the second, you can do this with slicing like this:
def doubleWord(word):
return word[len(word) // 2:] == word[:len(word) // 2]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With