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))
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))
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.
B is correct
is correct