A325)Could you please help me to solve this problem? Problem: Write ML function(
ID: 3581118 • Letter: A
Question
A325)Could you please help me to solve this problem?
Problem:
Write ML function(s) (ONLY WITH META LANGUAGE, ML. NOT OTHER PROGRAMMING LANGUAGES) to find the number of vowels and nonvowels in the strings sent as parameter in a list, and returns the strings and their count of vowels and nonvowels in a record list.
Sample Run:
-find([“good”,”luck”,”on”,”your”,”homework”]);
val it =
[{word="good",vowels=2,nonvowels=2},{ word="luck,vowels=1,nonvowels=3},
{ word="on",vowels=1,nonvowels=1},{ word="your",vowels=2,nonvowels=2 },
{ word="homework",vowels=3,nonvowels=5 }] : wrdrec list
Note:
Use the following list in your program to specify the vowels.
val vowels=[#”a”, #”e”, #”i”, #”o”, #”u”];
Use the explode function which changes a string to a char list.
- explode "abc";
val it = [#"a",#"b",#"c"] : char list
You can write as many functions as needed.
Do not forget to declare your types.
Explanation / Answer
Python:
vowels = 'aeiou'
ip_str = '"good","luck","on","your","homework"'
# uncomment to take input from the user
#ip_str = input("Enter a string: ")
ip_str = ip_str.casefold()
count = {}.fromkeys(vowels,0)
for char in ip_str:
if char in count:
count[char] += 1
print(count)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.