Question
Q1 . Write a code that takes a string, say str1 and counts the number of lower case vowels contained in the string str1 and
Q1. Write a code that takes a string, say str1 and counts the number of lower case vowels contained in the string str1 and assigns it to a variable called num. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'.( For example, for a given string 'mehmet guler',the code will return 4.)
Q2. You can generate a list using list conditionals. The code below is an example for a list conditional: L1 = [i for i in range(10)] Using a list conditional, write the python code that generates the list of vovels in a given string.( For example if the given string is str1 = 'mehmet guler' then the list should be ['e', 'e', 'u', 'e'].)
Q3. Write a lambda function which takes an input x and generates a list from 0 upto x-1. (For example if the input is x=5, then it returns the following list: [0,1,2,3,4])
Q5. Assume there are two dictionaries called Mid1 and Mid2. The dictionary Mid2 only includes a subset of Mid1. You want to calculate a weighted average of these two dictionaries and write it to a new dictionary called Avg like the following: - If an entry exists in both of the dictionaries (Mid1 and Mid2), then take the average of them and set it as the value at the new dictionary Avg.. - Otherwise (i.e., if an entry is only at the first list), then directly write the value in the first dictionary as the new value. Note that there are no any other options, i.e. there are no entries that exist Mid2 but do not exist in Mid1.
For example, if two dictionaries are given as follows, Mid1 = {'S1': 55, 'S2': 50, 'S3': 70} Mid2 = {'S1': 95, 'S3': 90, }
then the resulting dictionary Avg will be Avg = {'S1': 75, 'S2': 50, 'S3': 80}
Write the required python code.
Q6. Write a map function which reduces the value of every item in a given list by 1. (For example if the list is [2,5,3,8] then the output will be [1,4,2,7].)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started