to print and count number of matching vowels in a pair of strings

147 views Asked by At

hey guys I got this question on a test , has been bugging me for days now . best i could come up with was to convert it into sets and use set intersection , but that gives consnants too plus it does not tell how many times the vowel is occuring .

a="Asish"
b="Sankar"
a = list(a.lower())
#print(a)
b = list(b.lower())
a = set(a)
b = set(b)
print(a &b)

expected output: number of matching vowel cases are :0

sample input 2- a=Asish b=sashank sample output- a number of times matching vowels occured - 1

1

There are 1 answers

3
Amrit Pangeni On

My Approach will be like this:

a = "Aasish"
b = "Sankiar"
a = a.lower()
b = b.lower()
vowels_count = 0
repeat_count = []
for i in a:
    if i in b:
        if i in "aeiou" and i not in repeat_count:
            print("Matching Vowels:", i)
            print(f"Vowel '{i}' appeared total of {int(a.count(i)) + int(b.count(i)) } times in two strings.")
            repeat_count.append(i)

Output:

Matching Vowels: a
Vowel 'a' appeared total of 4 times in two strings.
Matching Vowels: i
Vowel 'i' appeared total of 2 times in two strings.