fork download
  1. def func(s):
  2. for l in range(1, len(s) + 1):
  3. r = s[:l]
  4. if len(r) * 2 > len(s):
  5. return s
  6. f = True
  7. for m in range(l * 2, len(s) + 1, l):
  8. if r != s[m - l:m]:
  9. f = False
  10. break
  11. if f:
  12. break
  13. return r
  14.  
  15. print(func('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'))
  16. print(func('123412312341231234123123412312341231234123'))
  17. print(func('oxoxoxoxoxoxoxoxxoxoxoxoxoxoxoxoxx'))
  18. print(func('abac'))
  19.  
Success #stdin #stdout 0.1s 10104KB
stdin
Standard input is empty
stdout
a
1234123
oxoxoxoxoxoxoxoxx
abac