I have a problem with multiple list conditions:
listionary = [{u'city': u'paris', u'id': u'1', u'name': u'paul'},
{u'city': u'madrid', u'id': u'2', u'name': u'paul'},
{u'city': u'berlin', u'id': u'3', u'name': u'tom'},
{u'city': u'madrid', u'id': u'4', u'name': u'tom'}]
I am trying to remove items that satisfy both conditions at the same time.
[elem for elem in listionary if (elem.get('name')!='paul' and elem.get('city')!='madrid')]
In this case, the element is deleted if at least one condition is met, am I trying to do this in several ways, by any ideas?
Expected Result:
[{u'city': u'paris', u'id': u'1', u'name': u'paul'}
{u'city': u'berlin', u'id': u'3', u'name': u'tom'}
{u'city': u'madrid', u'id': u'4', u'name': u'tom'}]
I would like to remove an element that meets both conditions.
source
share