Exam PCAP-31-03 All QuestionsBrowse all questions from this exam
Question 32

What is the expected output of the following code?

myli = range (-2,2)

m = list(filter(lambda x: True if abs(x) < 1 else False, myli)) print(len(m))

    Correct Answer: B

    The range function creates a sequence from -2 to 1 (inclusive of -2 and exclusive of 2). The filter function, combined with the lambda function, filters out only those elements whose absolute value is less than 1. In this sequence, the only value that meets this criterion is 0. Therefore, the filtered list (m) contains only one element (0), and the length of this list is 1.

Discussion
DKAT2023Option: B

B is correct

Dave304409Option: B

is correct