PYTHON Remove repetitive chars from string -


this question has answer here:

i have string name = "aaron" , remove vowels. using remove() if char repetive letter 'a' in case stays in string. suggestions ? here code :

def disemvowel(word):     word_as_list = list(word.lower())     print(word_as_list)     vowels = ["a", "e", "i", "o", "u"]     char in word_as_list:         v in vowels :              if char == v :                  word_as_list.remove(v)     return "".join(word_as_list)  print(disemvowel("aaaron")) 

as other people have said, list comprehension way go:

def disemvowel(word):     word = word.lower()     vowels = ["a" , "e", "i", "o", "u"]     return "".join([char char in word if char not in vowels])   print disemvowel("aaaallbag") 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -