Anti vowel help


#1

why doesnt this work?

def anti_vowel(text):
  word = ""
  v = [a,e,i,o,u,A,E,I,O,U]
  for x in text:
    if x == v:
      x = ""
      word = word + x
    else:
      x = x
      word = word + x
  return word

#2

The list should be of strings, not identifiers.

Or. just make the list into a string

v = "aeiouAEIOU"

Should be,

if x in v:

Extra study

if x in v:
    x = ""
word = word + x

If the following is new to you, set it aside until you get more exposure to advanced topics. The construct is known as a Python ternary statement.

word += "" if x in v else x

#3

thanks that helped, it has been a while since i last worked on python and i cant seem to remember the whole “if x in v” part. im comfortable with if else statements im just struggling to remember using the word “in”. would you happen to know what exercise covers it so i can go back and look over it.


#4

Will need to go through the new track when things settle down on the migration. We cannot discuss for loops without introducing in.

in is a very powerful operator when we consider that it is an iterator.

# iterating a range
# i will be an index of n

for i in range(len(n)):    

# iterating an iterable
# item will be a value in items

for item in items:

The exercise uses a for loop so there’s the first instance of the operator. By inference we can use the operator in an if statement…

# 0 <= r <= 255

if r in range(256):

and the above example of x in v.


#5

i can’t believe i completely forgot about using “in” in for loops thanks that clears things up.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.