Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- objects = {
- 'A': {'Red', 'Ford'},
- 'B': {'Red', 'Ford'},
- 'C': {'Blue', 'Ford'},
- 'D': {'Green', 'Volvo'},
- }
- attributes = set()
- for atts in objects.values():
- attributes |= atts
- attribute2objects = {att: set(k for k, v in objects.items() if att in v) for att in attributes}
- diffby1 = set()
- for att1 in attribute2objects:
- for att2 in attribute2objects:
- if att1 != att2:
- ob1 = attribute2objects[att1]
- ob2 = attribute2objects[att2]
- if len(ob2) > len(ob2):
- ob1, ob2 = ob2, ob1
- att1, att2 = att2, att1
- if len(ob1 - ob2) == 1 and len(ob2 - ob1) == 0:
- diffby1.add((att1, att2))
- print(sorted(diffby1))
Add Comment
Please, Sign In to add comment