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')
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].
- [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]
Correct Answer:
[x for x in w if x in v]
need an explanation for this answer? contact us directly to get an explanation for this answer