1

I am finding hard myself to filter a basic need: I have a list and I have to filter it by an value of the items:
My code:

list1=[{"a":865,"b":1},{"a":56,"b":6},{"a":995,"b":1,"c":5},{"a":1,"b":42}]
a=filter(lambda x:x["b"]==1, list1)
print a

I get the valid output, but if i want to update my filter with a==865 and b==1, i get an invalid syntax error:

a=filter(lambda x:x["a"]==865 && x["b"]==1, list1)
print a

Kindly help. Thanks in advance.

0

1 Answer 1

3

Replace && with and. That should do it! The docs (python 2)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.