Remove all vowels from a string in Python.

This Python function removes all the vowels from a given string.

Problem

Write a Python function that takes in a string and returns a new string with all the vowels removed.
Example input:
"Hello world!"
Example output:
"Hll wrld!"

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def remove_vowels(string):
    vowels = ['a', 'e', 'i', 'o', 'u']
    new_string = ''
    for char in string:
        if char.lower() not in vowels:
            new_string += char
    return new_string

print(remove_vowels('Hello world!'))



The solution is optimal because it uses a for loop to iterate through the string and check if each character is a vowel.
If it is not a vowel, it is added to the new string.


A.I. Evaluation of the Solution

The candidate's solution is optimal because it uses a for loop to iterate through the string and check if each character is a vowel. If it is not a vowel, it is added to the new string.

Evaluated at: 2022-11-24 00:16:05