Question: 1. Write a function consonants_lc(s) that takes as input a string s and uses a list comprehension to create and return a list containing the

1. Write a function consonants_lc(s) that takes as input a string s and uses a list comprehension to create and return a list containing the consonants (if any) in s. For example: >>> consonants_lc('computer') result: ['c', 'm', 'p', 't', 'r'] >>> consonants_1c('science') result: ['s', 'c', 'n', 'c'] >>> consonants_lc('aeiou') result: [] You may assume that the string s contains only lowercase letters, and thus any letter that is not a vowel (i.e., any letter other than 'a', 'e', 'i', 'o', or 'u') is a consonant. This version of the function may not use recursion. Hints: . Your list comprehension will need an if clause. . In the same way that we've used the in operator to check for whether a letter is a vowel, you can use the not in operator to check if a letter is not a vowel. Here are two examples of expressions that use not in: : python >>> 'i' not in result: True team >>> 't not in 'test result: False 2. Write a function consonants_rec(s) that takes as input a string s and uses recursion to create and return a list containing the consonants (if any) in s. In other words, this function will do the same thing as the previous function, but it must use recursion instead of a list comprehension. For example: >>> consonants_rec('computer') result: ['c', 'm', 'p', 't', 'r'] Here again, you may assume that the string s contains only lowercase letters. This version of the function may not use a list comprehension
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
