Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Problem Solving/replace whitespaces with underscores.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re


Input = input("Please enter a string: ")
def replace_white_spaces_with_underscores(input_string):
list_input = list(input_string)
final_string = " "
white_spaces = []
for match in re.finditer('\s', input_string):
white_spaces.append(match.start())

for i in range(len(white_spaces)):
list_input[white_spaces[i]] = "_"
return final_string.join(list_input)

print(replace_white_spaces_with_underscores(Input))