Reputation: 37
i try to make an error prevention, in which I look if their is a double definition.
For example:
json1 = {
"a": "python is good",
"b": "i like java",
"c": "python is good"
}
I want to iterate over the values and find out if I got the same value at another key.
To get a message like: "ERROR: double definition"
Is their a good way to compare these?
Upvotes: 0
Views: 160
Reputation: 1302
You can use length(len()
function) to compare them.
len(set(json1.values())) == len(json1.values())
You can use this in print like this:
print('ERROR: double definition' if len(set(json1.values())) != len(json1.values()) else 'All good')
Upvotes: 1