Guest User

Untitled

a guest
Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. objects = {
  2. 'A': {'Red', 'Ford'},
  3. 'B': {'Red', 'Ford'},
  4. 'C': {'Blue', 'Ford'},
  5. 'D': {'Green', 'Volvo'},
  6. }
  7.  
  8. attributes = set()
  9. for atts in objects.values():
  10. attributes |= atts
  11. attribute2objects = {att: set(k for k, v in objects.items() if att in v) for att in attributes}
  12. diffby1 = set()
  13. for att1 in attribute2objects:
  14. for att2 in attribute2objects:
  15. if att1 != att2:
  16. ob1 = attribute2objects[att1]
  17. ob2 = attribute2objects[att2]
  18. if len(ob2) > len(ob2):
  19. ob1, ob2 = ob2, ob1
  20. att1, att2 = att2, att1
  21. if len(ob1 - ob2) == 1 and len(ob2 - ob1) == 0:
  22. diffby1.add((att1, att2))
  23. print(sorted(diffby1))
Add Comment
Please, Sign In to add comment