Remove char at specific index - python
Use slicing, rebuilding the string minus the index you want to remove:
newstr = oldstr[:4] + oldstr[5:]
as a sidenote, replace
doesn't have to move all zeros. If you just want to remove the first specify count
to 1:
'asd0asd0'.replace('0','',1)
Out:
'asdasd0'
This is my generic solution for any string s
and any index i
:
def remove_at(i, s):
return s[:i] + s[i+1:]