Answers for "can you edit string.punctuation"

1

can you edit string.punctuation

>>> from string import punctuation
>>> from re import sub
>>> 
>>> string = "\Fred-Daniels!"
>>> translator = str.maketrans('','', sub('\-', '', punctuation))
>>> string
'\\Fred-Daniels!'
>>> string = string.translate(translator)
>>> string
'Fred-Daniels'
Posted by: Guest on November-27-2020
1

can you edit string.punctuation

>>> name = '\\test-1.'
>>> valid_characters = 'abcdefghijklmnopqrstuvwxyz1234567890- '
>>> filtered_name = ''.join([ x for x in name if x.lower() in valid_characters ])
>>> print(filtered_name)
test-1
Posted by: Guest on November-27-2020

Code answers related to "can you edit string.punctuation"

Python Answers by Framework

Browse Popular Code Answers by Language