PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 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))

Show Answer
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

2 comments
Sign in to comment
DKAT2023Option: B
Jul 1, 2024

B is correct

Dave304409Option: B
Jul 9, 2024

is correct