fork download
  1. def f(s):h=len(s)/2;r=s[:h]+'|'+s[h:];return s and max(r*(r==r[::-1]),f(s[1:]),f(s[:-1]),key=len)
  2.  
  3. for s in ("Hello World", "abcba", "Hulluh", "abcdefggfedcba", "abcdefggfabc", "AbbA"):
  4. print '%-14s -> %s' % (s,f(s))
Success #stdin #stdout 0.09s 9016KB
stdin
Standard input is empty
stdout
Hello World    -> l|l
abcba          -> 
Hulluh         -> ul|lu
abcdefggfedcba -> abcdefg|gfedcba
abcdefggfabc   -> fg|gf
AbbA           -> Ab|bA