8. anti_vowel. Something extraordinary


#1

I found the exercise too difficult. However, I had a clue:

vowels = ("aeiouAEIOU")
def anti_vowel(text):
    linword = []
    for l in text:
        if l in vowels:
            pass
        else:
            linword.append(l)
    wholeword = ''.join(linword)
    print wholeword
    

print anti_vowel(raw_input("Put sth: "))

Everything is OK, it works. The main issue is I didn't understand anything((

I'd thought I will do it in the similar way that we've done in previous exercise. I mean from Loops, 12 For your A:

phrase = "A bird in the hand..."

# Add your for loop
for char in phrase:
    
    if char == "A" or char == "a":
        print "X",
    else:
        print char,




#Don't delete this print statement!
print

but 1st is better. So could smo tell me in which lesson we have learnt it ?
Thank you!


#2

The Practice makes Perfect exercises are a compilation of all the exercises you have done before so just remember to clearly grasp all the concepts you do and don't feel shy to look back and review what you have done in the past. :slight_smile:


#3

Thank you for your attention and advice. Have you done the exercise in the same way or you have another version? I need to finish it comprehensively. I turned over almose all exercises but nothing happened. Still I don't know how it works.(( So I'm asking, if smo solved it in the same way, direct me how those come up with such sophisticated code and which resources they used or explain me in a penguin way)))


#4

I can explain to you what is happening in your code through comments,


#5

Could you clarify ?

if l in vowels: #in this case vowels = "aeiouAEIOU"

Does vowels check every letter from "aeiouAEIOU" whether they are similar or not? And what role plays in?

Also, sorry for my stupidity, I didn't catch what the .join() is ?


#6

Your for loop is looping through every character in the string that you parse,

So that if statement is basically saying,

if any letter in the string contains a vowel do not include it.

''.join() converts lists into strings.


#7

Python's in construct, when used with an if statement, lets you loop through all the members of a collection (in this case a string) and see if there's a member in the string that's equal to the pattern, our pattern is a letter source

in short, in is useful to check if something exist inside a list/string/tuple. in check for you of the pattern you look for is present, super nice :slight_smile:


#8

My gratitudes:relaxed:. Everything makes sense


#9

Great answer! The source ,also, is really useful. Thank you!


#10

So far, I've been searching sites, materials where I can find useful algorithms. And I hope you can help me))


#11

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