Why do the following two filter expressions return the same result?
A = [(1,(1,2,3))]
A1 = filter(lambda (a,b): b, A)
A2 = filter(lambda ab: ab, A)
A1 == A2
>>>> True
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
filterfilters out arguments that when passed into the function, returns aFalse-ish value. Both(1, 2, 3)and(1, (1, 2, 3))returnTruein a boolean context, and therefore remain in the returned list.You want
mapinstead.FYI, the follwing values are
False-ish values, while everything else isTrue-ish: