How can I remove multiple characters in a list?

后端 未结 5 890
天命终不由人
天命终不由人 2020-12-11 04:56

Having such list:

x = [\'+5556\', \'-1539\', \'-99\',\'+1500\']

How can I remove + and - in nice way?

This works but I\'m looking f

5条回答
  •  独厮守ぢ
    2020-12-11 05:22

    basestr ="HhEEeLLlOOFROlMTHEOTHERSIDEooEEEEEE"
    
    def replacer (basestr, toBeRemove, newchar) :
        for i in toBeRemove :
            if i in basestr :
            basestr = basestr.replace(i, newchar)
        return basestr
    
    
    
    newstring = replacer(basestr,['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'], "")
    
    print(basestr)
    print(newstring)
    

    Output :

    HhEEeLLlOOFROlMTHEOTHERSIDEooEEEEEE

    helloo

提交回复
热议问题