9th Jan 2023, 2:13 PM
ViShal Bhoi
ViShal Bhoi - avatar
2 Answers
+ 1
q() is not defined do not indent big=... if it is not part of the function.
9th Jan 2023, 2:18 PM
Lisa
Lisa - avatar
0
ViShal Bhoi Yes, your indentation is wrong, as Lisa said. filter expects a function that returns a boolean. Either modify your function or use map instead. a=[10,20,30,40,50,60,70,80,90] def plus10(x): return x+10 #map uses function with return value ten_more = list(map(plus10, a)) print(ten_more) def gt40(x): return x>40 #filter uses function that return a boolean (True or False) above_40 = list(filter(gt40, a)) print(above_40) #does not work as expected test1 = list(map(gt40, a)) print(test1) #does not work at all test2 = list(filter(plus10, a)) print(test2)
10th Jan 2023, 12:48 AM
Bob_Li
Bob_Li - avatar