You can check if two dictionaries are identical with ==
In [2]: {'1':'A','2':'B'}=={'2':'B','1':'A'}
Out[2]: True
Therefore to check if JSON
exists in my_list
you can simply do
if JSON in my_list:
#blahblah
Update:
To use set
with your data, you can define your own subclass and implement __hash__()
method. You can start from here:
class MyJSON(dict):
def __hash__(self):
return hash(json.dumps(self,sort_keys=True))
Example:
a=MyJSON({'1':'A','2':'B'})
b=MyJSON({'1':'A','2':'C'})
c=MyJSON({'2':'B','1':'A'}) ## should be equal to a
print a==c # should be True
my_set=set()
my_set.add(a)
my_set.add(b)
my_set.add(c)
for item in my_set:
print item,
## output is {'1': 'A', '2': 'C'} {'1': 'A', '2': 'B'}