Reputation: 301
How to check if the first three letters in the string are the same as three last letters reversed. They can't overlap. For example:
"karak" -> False
"kaakaak" -> True
Figured out that like this I can check out first three and last three reversed letters of string:
if s[:3] == s[-3:][::-1]:
But how to check if they are overlaping or not?
Upvotes: 1
Views: 79
Reputation: 31915
Checking length and compare first 3 letters with last 3 letters:
is_equal = True if len(s) >= 6 and s[:3] == s[-3:][::-1] else False
Upvotes: 4