Example HTML page

Python Exercise 15

The following questions are from List and Dictionary Comprehension

1.Write a python script to read ’10’ elements from the user and append it in to a list. Using list Comprehensions create another list and store all the even number in the original list.

2.Write a python script to read ’10’ elements from the user and append it in to a list. Using list Comprehensions create another list and store the names which starts with letter ‘s’.

3. Write a python script to read ‘6’ elements from the user and append it in to a list. Using list Comprehensions create another list and store the square root of each number in the original list.

4. Write a python script to read six employee names along with their experience and append it in to a dictionary. Using dictionary comprehensions print the name and experience of the employee who are  having more than 10 years experience.
Input:
{‘aaa’:17, ‘bbb’:13,’ccc’:9,’ddd’:1,’eee’:12,’fff’:6}
Output:
{aaa’:17,’bbb’:13,’eee’:12}

5. Write a python script to read six employee names along with their experience and append it in to a dictionary. The employee is eligible for promotion if he is having more than 6 years experience.

Input:
{‘aaa’:7, ‘bbb’:3,’ccc’:9,’ddd’:1,’eee’:2,’fff’:10}
Output:
{‘aaa’:’eligible’,’ccc’:’eligible’,’fff’:’eligible’}

6. Write a python script to read the following string and find how many time each letter/number appeared in the string.
str = “This is sudhakar and my mobile number is 9985327199”

7. Write a python script to read the name and mobile numbers of ‘5’ persons and print the mobile number is valid or not. The input is given below, A mobile number is invalid if it starts with less than digit ‘5’. use dictionary comprehension to store the final dictionary result
Input:
a 9856752589
b 0123123456
c 7895456215
d 1457895235
e 4879565221
Output:
Invalid Mobile numbers are:
{‘b’:0123123456, ‘d’:1457895235, ‘e’:4879565221}

8. Write a python script to read ‘6’ numbers from the user and print the sum of squares of even numbers in the list.
a. Use map, filter and reduce functions
b. Using only lambda functions
c. Use list comprehensions

9. Append the following elements in to a list and find the transpose of a given matrix using list comprehension.

Input matrix = [[1, 2, 3, 4], [4, 5, 6, 8]]

10. Append the following elements in to a list and find the transpose of a given matrix using list comprehension.

Input matrix = [[1,2],[3,4],[5,6],[7,8]]

11. Write a python script to read ’10’ elements and append the elements in to the list. Print the given number is even or odd using list comprehension.

Input:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Output:

[‘Even’, ‘Odd’, ‘Even’, ‘Odd’, ‘Even’, ‘Odd’, ‘Even’, ‘Odd’, ‘Even’, ‘Odd’]

You can refer the following post to get some idea about list comprehension

List Comprehension

Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest