Answer:
The solution code is written in Python 3:
- letterList = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
- 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
-
- def common_letters(strings):
- result = []
-
- for l in letterList:
- count = 0
- for s in strings:
- if l in s:
- count = count + 1
-
- if(count == len(strings)):
- result.append(l)
-
- return result
-
- print(common_letters(["statistics", "computer science", "biology"]))
- print(common_letters(["apple", "orange", "grape"]))
Step-by-step explanation:
Firstly, we can create a letter list that includes the letters from a to z.
Next we create a function common_letters that take one parameter (Line 4).
Create a result list to hold the output the function (Line 5).
Next, we create a for-loop to traverse through each of the letter in the letterList and then create another for loop to traverse through every single string in the input strings and then check if the letter found in a current string. If so increment the count by one. (Line 7 -11).
Logically if the number of occurrence of a single letters equal to number of words in the strings list, this means the letter is common to all the words (Line 13). We can append this letter, l, to result list (Line 14) and return it as the output (Line 16).
We can test the functions using two sample word list (Line 18-19) and the output is as follows:
['i']
['a', 'e']