“czy możesz edytować string.puncation” Kod odpowiedzi

czy możesz edytować string.puncation

>>> 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'
Gentle Grasshopper

czy możesz edytować string.puncation

>>> 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
Gentle Grasshopper

Odpowiedzi podobne do “czy możesz edytować string.puncation”

Pytania podobne do “czy możesz edytować string.puncation”

Więcej pokrewnych odpowiedzi na “czy możesz edytować string.puncation” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu