diff --git a/Problem Solving/replace whitespaces with underscores.py b/Problem Solving/replace whitespaces with underscores.py new file mode 100644 index 0000000..e37da41 --- /dev/null +++ b/Problem Solving/replace whitespaces with underscores.py @@ -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))