My Report

Python List Comprehension Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Write the list comprehension to pick out only negative integers from a given list ‘l’.

2. What will be the output of the following Python code?

s=["pune", "mumbai", "delhi"]
[(w.upper(), len(w)) for w in s]

3. What will be the output of the following Python code?

l1=[10, 20, 30]
l2=[-10, -20, -30]
l3=[x+y for x, y in zip(l1, l2)]
l3

4. What will be the output of the following Python code?

l1=[2,4,6]
l2=[-2,-4,-6]
for i in zip(l1, l2):
	print(i)

5. What will be the output of the following Python code?

l1=[1,2,3]
l2=[4,5,6]
l3=[7,8,9]
for x, y, z in zip(l1, l2, l3):
	print(x, y, z)

6. What will be the output of the following Python code?

l=[1,2,3,4,5]
[x&1 for x in l]

7. What will be the output of the following Python code?

import math
[str(round(math.pi)) for i in range (1, 6)]

8. Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9].

9. What will be the output of the following Python code?

l=[[1 ,2, 3], [4, 5, 6], [7, 8, 9]]
[[row[i] for row in l] for i in range(3)]

10. What will be the output of the following Python code?

l1=[1,2,3]
l2=[4,5,6]
[x*y for x in l1 for y in l2]

 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.