Disemvowel Trolls

Trolls are attacking your comment section!
A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat.
Your task is to write a function that takes a string and return a new string with all vowels removed.
For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!".

def disemvowel(string):
    s = 'aeiouAEIOU'
    for i in range(len(s)):
        string = string.replace(s[i], '')
    return string

我犯了两个问题

1. str 是不可以直接用index来改变赋值的

2. replace的时候没有考虑string的长度已经发生改变

猜你喜欢

转载自www.cnblogs.com/david-1989/p/10312471.html