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

sid597
  • 999
  • 3
  • 16
  • 31

1 Answers1

1

you can probably use count() method

like:

string = "aaabbaacdeef"
string.count('a') # returns the count of 'a' in string
>>> 5
AnnShress
  • 477
  • 1
  • 5
  • 11