8.Anti_vowel


#1

Hi, Can anyone tell me how do I club the elements in the list.
I used join but didn't work out.


#2

please post raw code , thanks!


#3

def anti_vowel(text):
j=[]

for i in text:
    print (i)
    j+=i

    print ''.join(j)

    for y in j:
        if y=='u':
            j.remove('u')

        elif y=='a':
            j.remove('a')

        elif y=='e':
            j.remove('e')

        elif y=='i':
            j.remove('i')

        elif y=='o':
            j.remove('o')

        elif y=='A':
            j.remove('A')

        elif y=='E':
            j.remove('E')

        elif y=='I':
            j.remove('I')

        elif y=='O':
            j.remove('O')

        elif y=='U':
            j.remove('U')


return j

#4

Your code have many repeated parts tho and it can be made more efficient, not considering that at the moment , with respect to your code,

You need to use join() method on your list j so it able to returned as a string.

we can reduce this line by...

 if y=='u':
                j.remove('u')
    
            elif y=='a':
                j.remove('a')
    
            elif y=='e':
                j.remove('e')
    
            elif y=='i':
                j.remove('i')
    
            elif y=='o':
                j.remove('o')
    
            elif y=='A':
                j.remove('A')
    
            elif y=='E':
                j.remove('E')
    
            elif y=='I':
                j.remove('I')
    
            elif y=='O':
                j.remove('O')
    
            elif y=='U':
                j.remove('U')

by this..

if y in "aeiouAEIOU":
    #code

#5

Thanks but still I am getting the same error. I used join but I think after j+=(i)...I had to do something as it's taking the single character of 'text' as an element of the list 'j'. Hence, the error.
Can you help me in that particular problem ?


#6

Can you show me the updated code ? use 3 ticks format the code (surround code with it) or can use <\> after selecting the code.


#7

def anti_vowel(text):
j=[]
text='anshul'
for i in text:
print (i)
j+=i
print ''.join(i)
for y in j:
if y in "aeiouAEIOU":
j.remove(y)
return j
I didn't what 3 ticks mean here...you mean """....srry I am a newbie in coding.


#8

You have to convert your list to string at this line instead of doing it before. use join() method,right now you directly returning the list.


#9

def anti_vowel(text):
j=[]

for i in text:
    print (i)
    j+=i


    for y in j:
        if y in "aeiouAEIOU":
            j.remove(y)

text=''.join(j)
return text

Works well!
Thanls @greentreemee


#10

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