Remove char at specific index - python

后端 未结 8 1976
清酒与你
清酒与你 2020-12-01 05:48

I have a string that has two \"0\" (str) in it and I want to remove only the \"0\" (str) at index 4

I have tried calling .replace but obviously that removes all \"0\

相关标签:
8条回答
  • 2020-12-01 06:42
    rem = lambda x, unwanted : ''.join([ c for i, c in enumerate(x) if i != unwanted])
    rem('1230004', 4)
    '123004'
    
    0 讨论(0)
  • 2020-12-01 06:47

    Try this code:

    s = input() 
    a = int(input()) 
    b = s.replace(s[a],'')
    print(b)
    
    0 讨论(0)
提交回复
热议问题