using recursion python Consider the English alphabet consisting of 26 lowercase letters: a, b, c, · · ·, x, y, z. • To this order, letters appear earlier are defined smaller. For example, the letter a is smaller than the letter b, and z is the largest letter since it appears last in the alphabet. • The least letter of an English word is the smallest letter that appears in that word. For example, the least letter of “Saturday” is “a”, and the least letter of “hello” is “e”. You are asked to write a program consisting of a function and a main interface as follows. (a) function recur_least_letters(l): Goal: collects all the least letters of words in list l (one least letter for each word) and returns the string of the obtained least letters in the order that the corresponding words appear in list l. • Input: a list l of English words • Output: string of all the least letters of words appearing in list l • Example: input: l = [‘today’, ‘is’, ‘saturday’] → output: “aia” Recursion is strictly required. (a) Base case: write return statements for the cases that len(l) = 0 and/or len(l) = 1 (b) Recursive relation: if len(l) ≥ 2, then split l into two smaller lists - one contains the first element of l and the other contains the rest of l. Then reduce the task for l to the analogous tasks for the two smaller lists. Hints. You may want to use methods such as list(), sorted(), etc. (b) main interface • Input: define the list variable input_s = [‘today’, ‘is’, ‘saturday’] • Output: apply the function recur_least_letters to input_s and print out the output, which should be “aia’.
using recursion python
Consider the English alphabet consisting of 26 lowercase letters: a, b, c, · · ·, x, y, z.
• To this order, letters appear earlier are defined smaller. For example, the letter a is
smaller than the letter b, and z is the largest letter since it appears last in the alphabet.
• The least letter of an English word is the smallest letter that appears in that word. For
example, the least letter of “Saturday” is “a”, and the least letter of “hello” is “e”.
You are asked to write a program consisting of a function and a main interface as follows.
(a) function recur_least_letters(l):
Goal: collects all the least letters of words in list l (one least letter for each word)
and returns the string of the obtained least letters in the order that the corresponding
words appear in list l.
• Input: a list l of English words
• Output: string of all the least letters of words appearing in list l
• Example: input: l = [‘today’, ‘is’, ‘saturday’]
→ output: “aia”
Recursion is strictly required.
(a) Base case: write return statements for the cases that len(l) = 0 and/or len(l) = 1
(b) Recursive relation: if len(l) ≥ 2, then split l into two smaller lists - one
contains the first element of l and the other contains the rest of l. Then reduce the
task for l to the analogous tasks for the two smaller lists.
Hints. You may want to use methods such as list(), sorted(), etc.
(b) main interface
• Input: define the list variable input_s = [‘today’, ‘is’, ‘saturday’]
• Output: apply the function recur_least_letters to input_s and print out the output,
which should be “aia’.
Step by step
Solved in 3 steps with 1 images