vowels = 'aeiou'
# take input from the user
ip_str = raw_input("Enter a string: ")
# make it suitable for caseless comparisions
ip_str = ip_str.casefold()
# make a dictionary with each vowel a key and value 0
count = {}.fromkeys(vowels,0)
# count the vowels
for char in ip_str:
if char in count:
count[char] += 1
print(count)
Error:
Line - ip_str = ip_str.casefold()
AttributeError: 'str' object has no attribute 'casefold'
Python 2.6 doesn't support the str.casefold()
method.
From the str.casefold()
documentation:
New in version 3.3.
You'll need to switch to Python 3.3 or up to be able to use it.
There are no good alternatives, short of implementing the Unicode casefolding algorithm yourself. See How do I case fold a string in Python 2?
However, since you are handling a bytestring here (and not Unicode), you could just use str.lower()
and be done with it.