List Comprehension
1.

What will be the output of the following Python code snippet?

k = [print(i) for i in my_string if i not in "aeiou"]
A.  

prints all the vowels in my_string

B.  

prints all the consonants in my_string

C.  

prints all characters of my_string that aren’t vowels

D.  

prints only on executing print(k)

2.

What will be the output of the following Python code snippet?

k = [print(i) for i in my_string if i not in "aeiou"]
A.  

prints all the vowels in my_string

B.  

prints all the consonants in my_string

C.  

prints all characters of my_string that aren’t vowels

D.  

prints only on executing print(k)

3.

What is the output of print(k) in the following Python code snippet?

k = [print(i) for i in my_string if i not in "aeiou"]
print(k)
A.  

all characters of my_string that aren’t vowels

B.  

a list of Nones

C.  

list of Trues

D.  

list of Falses

4.

What will be the output of the following Python code snippet?

my_string = "hello world"
k = [(i.upper(), len(i)) for i in my_string]
print(k)
A.  

[(‘HELLO’, 5), (‘WORLD’, 5)]

B.  

 [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]

C.  

[(‘HELLO WORLD’, 11)]

D.  

none of the mentioned

5.

Which of the following is the correct expansion of list_1 = [expr(i) for i in list_0 if func(i)]?

A.  
list_1 = []
for i in list_0:
    if func(i):
        list_1.append(i)
B.  
for i in list_0:
    if func(i):
        list_1.append(expr(i))
C.  
list_1 = []
for i in list_0:
    if func(i):
        list_1.append(expr(i))
D.  

none of the mentioned

6.

What will be the output of the following Python code snippet?

x = [i**+1 for i in range(3)]; print(x);
A.  

[0, 1, 2]

B.  

[1, 2, 5]

C.  

error, **+ is not a valid operator
 

D.  

error, ‘;’ is not allowed

7.

What will be the output of the following Python code snippet?

print([i.lower() for i in "HELLO"])
A.  

[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

B.  

‘hello’

C.  

[‘hello’]

D.  

hello

8.

What will be the output of the following Python code snippet?

A.  
print([i+j for i in "abc" for j in "def"])
B.  

[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]

C.  

[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

D.  

[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

9.

What will be the output of the following Python code snippet?

print([[i+j for i in "abc"] for j in "def"])
A.  

[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]

B.  

 [[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

C.  

[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]

D.  

[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

10.

What will be the output of the following Python code snippet?

print([if i%2==0: i; else: i+1; for i in range(4)])
A.  

[0, 2, 2, 4]

B.  

[1, 1, 3, 3]

C.  

error

D.  

none of the mentioned