Hi all,
I would like deleting specific characters from a string.
As an example, I would like to delete all of the '@' '&' in the string
'You are ben@orange?ente r&your&code' so that it becomes
'benorange?ente ryourcode'.
So far I have been doing it like:
str = 'You are ben@orange?ente r&your&code'
str = ''.join([ c for c in str if c not in ('@', '&')])
but that looks so ugly.. I am hoping to see nicer examples to acheive
the above..
Thanks.
Ben.
I would like deleting specific characters from a string.
As an example, I would like to delete all of the '@' '&' in the string
'You are ben@orange?ente r&your&code' so that it becomes
'benorange?ente ryourcode'.
So far I have been doing it like:
str = 'You are ben@orange?ente r&your&code'
str = ''.join([ c for c in str if c not in ('@', '&')])
but that looks so ugly.. I am hoping to see nicer examples to acheive
the above..
Thanks.
Ben.
Comment