def replace4(x):
if len(x) <= 1:
return x
if x[0] == x[len(x) - 1]:
return x[0] + x
return x + x[len(x) - 1]
| Function Call | Return Value | |||
|---|---|---|---|---|
| replace4('hello') | → | |||
| replace4('aba') | → | |||
| replace4(' world') | → | |||
| replace4('') | → | |||
| replace4('goodbye') | → | |||
| replace4('oof') | → | |||
| replace4('a') | → | |||
Experiment with this code on Gitpod.io