What will be the output of the following Python code? [code] a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return

What will be the output of the following Python code?
Code:
a = [5,5,6,7,7,7]
b = set(a)
def test(lst):
    if lst in b:
        return 1
    else:
        return 0
for i in  filter(test, a):
    print(i,end=" ")
A. 5 5 6
B. 5 6 7
C. 5 5 6 7 7 7
D. 5 6 7 7 7
 
Answer: c
Explanation: The filter function will return all the values from list a which are true when passed to function test. Since all the members of the set are non-duplicate members of the list, all of the values will return true. Hence all the values in the list are printed.
 

Tìm kiếm

Back
Top