0

I wanted to count the number of vowels in a string and did it like this

count =0
t='aeiou'
s='azcbobobegghaklhbjkhiohvghfaaaa'
for i in s:
    if i in t:
        count =count +1
print count        

before taking this approach I was trying it to do like

def isVowel(s):
    count=0
    for char in 'aeiou':
        t=s.find(char)
        if t>=0:
            count=count+1
            s=s[t:]
    return count

print isVowel('azcbobobegghakl')  

but here i faced the problem is that once char is taken as 'a' and thee whole loop is executed and now the value of char changes to 'e' so if there is there is another a in the string it is not counted .How can I resolve this problem in this approach

1

1 Answer 1

1

you can probably use count() method

like:

string = "aaabbaacdeef"
string.count('a') # returns the count of 'a' in string
>>> 5
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.