text: 
  Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".
  it should works correctly, but WHY !!!!
  def anti_vowel(text):
  vowels = ['a','e','i','o','u','A','E','I','O','U']
  l = list(text)
  word = ""
  for char in l:
  if char in vowels:
  l.remove(char)
  for x in l:
  word += x
  return word
  Every time you remove one item from list l, The length of list gets decreased and thus it cause to leave few vowels inside the list unremoved !
  for more clarification ---
  Ok , I get it . & Thanks for all bro BUT i can't Find another format that can run the code Correctly. So , if you have an answer for that PLEASE Help
  def anti_vowel(text):
  vowels = ['a','e','i','o','u','A','E','I','O','U']
  l = list(text)
  word = ""
  for char in l:
  if char in vowels:
  l.remove(char)
  for char in l:
  if char in vowels:
  l.remove(char)
  for x in l:
  word += x
  return word
  print anti_vowel("Hey look Words")
  i did my best & it works correctly but i still believe that there's a better solution for that if you have other suggestionshelp me Advance Thanks
  def anti_vowel(text):
  word = list(text)
  #checking each letter in word
  count = 0
  while count < len(word):
  if word[count] in "aeiouAEIOU":
  word.remove(word[count])
  else:
  count += 1
  return "".join(word)
  print(anti_vowel('Hey look Words!'))
  The problem arises when you remove a word with a for loop. You remove a vowel at index 1 and then the next letter is now at index 1. However, the for loop is still at index 1. Then the for loop moves to index 2, but it has skipped the letter that moved into index 1. I solved with by using a while loop, and not incrementing the count when I remove a letter.
  Hope this helps!
  def anti_vowel(text): new_string = "" vowels = ('a', 'e', 'i', 'o', 'u', 'A', 'I', 'E', 'O', 'U') for v in text: if v in vowels: text = text.replace(v, '') return textprint anti_vowel("Hey look Words!")
  output is : Hy lk Wrds!hope this will help
  Thanks Bro , This is another way to do it
  Thank You , This helped me a lot
  Thanks
  Why did you create the variable
  ?
  yeah ..there is no use of that string. without that variable you can solve that code! it will not affect the code anyway.just place # before it or just delete that line!def anti_vowel(text):vowels = ('a', 'e', 'i', 'o', 'u', 'A', 'I', 'E', 'O', 'U')for v in text:if v in vowels:text = text.replace(v, '')return textprint anti_vowel("Hey look Words!")
  here we go!!
  I used a slightly different way: instead of removing vowels from given parameter i added non-vowels characters to a new variable. Code (purged by too many debug prints :P):
  def anti_vowel(text):
  out= ""
  vowels=["a","e","i","o","u"]
  lower= text.lower()
  for char in range(len(text)):
  for v in vowels:
  if lower[char] == v:
  break
  else:
  out += text[char]
  return out
  anti_vowel("aRe")
  def anti_vowel(text): out_string = '' vowels = "aeiouAEIOU" for i in text: if i in vowels: continue else: out_string += i return out_stringYou can iterete strings like here, if char is in vowels string then continue loop to next iteration
  This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.