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)
all characters of my_string that aren’t vowels
a list of Nones
list of Trues
list of Falses
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)
[(‘HELLO’, 5), (‘WORLD’, 5)]
[(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
[(‘HELLO WORLD’, 11)]
none of the mentioned
x = [i**+1 for i in range(3)]; print(x);
[0, 1, 2]
[1, 2, 5]
error, **+ is not a valid operator
error, ‘;’ is not allowed
print([i.lower() for i in "HELLO"])
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
‘hello’
[‘hello’]
hello
print([i+j for i in "abc" for j in "def"])
[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]
[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]
print([[i+j for i in "abc"] for j in "def"])
print([if i%2==0: i; else: i+1; for i in range(4)])
[0, 2, 2, 4]
[1, 1, 3, 3]
error
[x**-1 for x in [(1, 2, 3)]]
[1/x for x in [(1, 2, 3)]]
[1/x for x in (1, 2, 3)]
What will be the output of the following Python code?
l=[1,2,3,4,5] [x&1 for x in l]
[1, 1, 1, 1, 1]
[1, 0, 1, 0, 1]
[1, 0, 0, 0, 0]
[0, 1, 0, 1, 0]
l1=[1,2,3] l2=[4,5,6] [x*y for x in l1 for y in l2]
[4, 8, 12, 5, 10, 15, 6, 12, 18]
[4, 10, 18]
[4, 5, 6, 8, 10, 12, 12, 15, 18]
[18, 12, 6, 15, 10, 5, 12, 8, 4]
[x<0 in l]
[x for x<0 in l]
[x in l for x<0]
[x for x in l if x<0]
s=["pune", "mumbai", "delhi"] [(w.upper(), len(w)) for w in s]
Error
[‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]
[PUNE, 4, MUMBAI, 6, DELHI, 5]
[(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]
l1=[10, 20, 30] l2=[-10, -20, -30] l3=[x+y for x, y in zip(l1, l2)] l3
0
[-20, -60, -80]
[0, 0, 0]
[x**3 for x in l]
[x^3 for x in l]
[x**3 in l]
[x^3 in l]
import math [str(round(math.pi)) for i in range (1, 6)]
[‘3’, ‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
[‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’, ‘3.141582’]
[‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
[‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’]
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')
[x for w in v if x in v]
[x for x in w if x in v]
[x for x in v if w in v]
[x for v in w for x in w]
[ord(ch) for ch in 'abc']
[97, 98, 99]
[‘97’, ‘98’, ‘99’]
[65, 66, 67]
t=32.00 for x in t: print(x)
[0]
[0.00]
[x in range(1, 1000) if x%3==0]
[x for x in range(1000) if x%3==0]
[x%3 for x in range(1, 1000)]
[x%3=0 for x in range(1, 1000)]
Write a list comprehension equivalent for the Python code shown below.
for i in range(1, 101): if int(i*0.5)==i*0.5: print(i)
[i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
[i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
[i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
[i for i in range(1, 100) if int(i*0.5)=(i*0.5)]