""" Write a program that takes a string as an input and prints it after removing all consecutive occurrences of repeated char...
""" | |
Write a program that takes a string as an input and prints it after removing all consecutive occurrences of repeated | |
character that is non vowel. | |
Example | |
Sample Input 1: | |
Hello my fellow peeps | |
Sample Output 1: | |
Helo my felow peeps | |
"""
| |
import time | |
input_string = input("Enter a string...\n") | |
start_time = time.time() | |
new_list = list() | |
vowel = ['a', 'e', 'i', 'o', 'u'] | |
for i in range(len(input_string) - 1): | |
if input_string[i].lower() in vowel: | |
new_list.append(input_string[i]) | |
elif input_string[i].lower() != input_string[i + 1].lower(): | |
new_list.append(input_string[i]) | |
new_list.append(input_string[-1:]) | |
print("Output String (Method 1) : ", ''.join(new_list)) | |
print("Time taken by Method 1 : ", time.time() - start_time) |
COMMENTS