How do I strip a string given a list of unwanted characters? Python -


is there way pass in list instead of char str.strip() in python? have been doing way:

unwanted = [c c in '!@#$%^&*(fghjkmn'] s = 'ffffofob*&%ar**^' u in unwanted:   s = s.strip(u) print s 

desired output, output correct there should sort of more elegant way how i'm coding above:

ofob*&%ar 

strip , friends take string representing set of characters, can skip loop:

>>> s = 'ffffofob*&%ar**^' >>> s.strip('!@#$%^&*(fghjkmn') 'ofob*&%ar' 

(the downside of things fn.rstrip(".png") seems work many filenames, doesn't work)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -