fork download
  1. # http://c...content-available-to-author-only...e.com/questions/51984/stretching-words/52011#52011
  2.  
  3. def f(s,t):
  4. for c in t:s=s.replace(c,'%',1)
  5. print s.replace('%','%s')%*(x*2for x in t)
  6.  
  7. f('abcdefghij', ['a','b','c'])
  8. #output: aabbccdefghij
  9.  
  10. f('lizard', ['i','a','r','d'])
  11. #output: liizaarrdd
  12.  
  13. f('coconut', ['c','o'])
  14. #ouput: ccooconut or coccoonut or ccocoonut
  15.  
  16. f('onomatopoeia', ['o','o','a','o','o'])
  17. #output: oonoomaatoopooeia
  18.  
  19. f('onomatopoeia', ['o','a','o'])
  20. #output: oonomaatoopoeia or onoomaatoopoeia or oonomaatopooeia etc.
Compilation error #stdin compilation error #stdout 0.01s 7688KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError:   File "prog.py", line 5
    print s.replace('%','%s')%*(x*2for x in t)
                              ^
SyntaxError: invalid syntax

stdout
Standard output is empty