delete common dictionaries in list based on a value
Posted
by
pythoonatic
on Stack Overflow
See other posts from Stack Overflow
or by pythoonatic
Published on 2014-08-20T16:08:33Z
Indexed on
2014/08/20
16:20 UTC
Read the original article
Hit count: 162
How would I delete all corresponding dictionaries in a list of dictionaries based on one of the dictionaries having a character in it.
data = [
{ 'x' : 'a', 'y' : '1' },
{ 'x' : 'a', 'y' : '1/1' },
{ 'x' : 'a', 'y' : '2' },
{ 'x' : 'b', 'y' : '1' },
{ 'x' : 'b', 'y' : '1' },
{ 'x' : 'b', 'y' : '1' },
]
For example, how would I delete all of the x = a
due to one of the y
in the x=a
having a /
in it? Based on the example data above, here is where I would like to get to:
cleaneddata = [
{ 'x' : 'b', 'y' : '1' },
{ 'x' : 'b', 'y' : '1' },
{ 'x' : 'b', 'y' : '1' },
]
© Stack Overflow or respective owner