I have a variable:
x = 4
And I have a list:
list = [{'name': u'A', 'value': '1'}, {'name': u'B', 'value': '4'}, {'name': u'C', 'value': '2'}]
How can I exclude/remove the element in list where value=x?
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.
A list comprehension is perfect for this.
You can also use
filter, but I believe list comprehensions are preferred in terms of style:edit: noticed your values are strings, so I added an int conversion.