snake format
The answer to your question
text_in=input("Enter text to format in snakecase: \n")
if text_in.isspace():
print("The string contains only spaces")
else:
text_out=text_in.lower().replace(' ', '_')
for ch in list([',','.','!','@','#','$','%','__']):
text_out=text_out.replace(ch, '')
text_out=text_out.strip('_')
print(text_out)
Answer to question with comments
text_in=input("Enter text to format in snakecase: \n")
if text_in.isspace(): #Checking for an empty string
print("The string contains only spaces")
else:
text_out=text_in.lower().replace(' ', '_') #changes the case of characters and replaces spaces with underscores
for ch in list([',','.','!','@','#','$','%','__']): #removes the specified characters
text_out=text_out.replace(ch, '')
text_out=text_out.strip('_') #Remove "_" characters at the beginning and at the end of the string
print(text_out)
Comments
Leave a comment