can you edit string punctuation

Solutions on MaxInterview for can you edit string punctuation by the best coders in the world

showing results for - "can you edit string punctuation"
Paul
13 Jan 2016
1>>> from string import punctuation
2>>> from re import sub
3>>> 
4>>> string = "\Fred-Daniels!"
5>>> translator = str.maketrans('','', sub('\-', '', punctuation))
6>>> string
7'\\Fred-Daniels!'
8>>> string = string.translate(translator)
9>>> string
10'Fred-Daniels'
11
Selim
31 Jun 2020
1>>> name = '\\test-1.'
2>>> valid_characters = 'abcdefghijklmnopqrstuvwxyz1234567890- '
3>>> filtered_name = ''.join([ x for x in name if x.lower() in valid_characters ])
4>>> print(filtered_name)
5test-1
6