How to erase letters at any position in a string in python? -


for example, string = 'xx22xx_1x_xxxx-xxxx', x can letters. want delete first 2 positions letters xx , seventh position 1, in order newstring = '22xx_x_xxxx-xxxx'. function erase letters @ specific positions?

this it:

def erase(string, positions):     return "".join([y x,y in enumerate(string) if x not in positions]) 

demo:

>>> s='xx22xx_1x_xxxx-xxxx' >>> erase(s, (0,1,7)) '22xx_x_xxxx-xxxx' >>> 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -