Question

Using Python: #Write a letterAppearance function that takes a string, str as argument #letterAppearance will count...

Using Python:

#Write a letterAppearance function that takes a string, str as argument
#letterAppearance will count the number of times each letter appears in a string
#using a dictionary. #letterAppearance returns only the letters that appear in the string.
#Capitalization should not matter
'''
letterAppearance('hello')
#{'h': 1, 'e': 1, 'l': 2, 'o': 1} letterAppearance('Hello')
#{'h': 1, 'e': 1, 'l': 2, 'o': 1} letterAppearance('mutation')
#{'m': 1, 'u': 1, 't': 2, 'a': 1, 'i': 1, 'o': 1, 'n': 1}
'''

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The answer to this question is as follows:

The code is as follows:

def letterAppearance(str1):
letter_freq = {}
for i in str1.lower():
#checking the character is already there then incrementing 1
if i in letter_freq:
letter_freq[i] += 1
#otherwise providing the 1
else:
letter_freq[i] = 1
return letter_freq
print(letterAppearance("mutation"))

The input and output is as follows:

1 - def letter Appearance(str1): 2 letter_freq = {} 3- for i in stri.lower(): 4. #checking the character is already there the

Add a comment
Know the answer?
Add Answer to:
Using Python: #Write a letterAppearance function that takes a string, str as argument #letterAppearance will count...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT