11. What is the output of the code shown below?
import math
[str(round(math.pi)) for i in range (1, 6)]
Correct Answer is : [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
12. What is the output of the code shown below?
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)
Correct Answer is : 39086
13. Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]
w="hello"
v=('a', 'e', 'i', 'o', 'u')
Correct Answer is : [x for x in w if x in v]
14. What is the output of the code shown below?
[ord(ch) for ch in 'abc']
Correct Answer is : [97, 98, 99]
15. What is the output of the code shown below?
t=32.00
[round((x-32)*5/9) for x in t]
Correct Answer is : Error
16. Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3.
Correct Answer is : [x for x in range(1000) if x%3==0]
17. Write a list comprehension equivalent for the code shown below:
for i in range(1, 101):
if int(i*0.5)==i*0.5:
print(i)
Correct Answer is : [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
18. What is the list comprehension equivalent for: list(map(lambda x:x**-1, [1, 2, 3]))
Correct Answer is : [x**-1 for x in [1, 2, 3]]
19. Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].
Correct Answer is : [(2**x) for x in range(0, 13)]
20. What is the list comprehension equivalent for:
{x : x is a whole number less than 20, x is even} (including zero)
Correct Answer is : [x for x in range(0, 20) if (x%2==0)]