Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’] [code]w="hello" v=('a', 'e',

Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]
Code:
w="hello"
v=('a', 'e', 'i', 'o', 'u')
A. [x for w in v if x in v]
B. [x for x in w if x in v]
C. [x for x in v if w in v]
D. [x for v in w for x in w]
 
Answer: b
Explanation: The tuple ‘v’ is used to generate a list containing only vowels in the string ‘w’. The result is a list containing only vowels present in the string “hello”. Hence the required list comprehension is: [x for x in w if x in v].
 

Tìm kiếm

Back
Top