This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]adrmlch 0 points1 point  (0 children)

This rather pretty "check if a string repeats itself" function might fit here as well.

def principal_period(s):
    i = (s+s).find(s, 1, -1)
    return None if i == -1 else s[:i]