fork download
  1. from itertools import combinations
  2.  
  3. lstA = ['Harry Potter','1984','50 Shades','Dracula']
  4. lstB = ['50 Shades','Dracula','1984','Harry Potter']
  5.  
  6. setA = set(combinations(lstA, 2))
  7. setB = set(combinations(lstB, 2))
  8.  
  9. result = setA - setB
  10.  
  11. print(result)
  12.  
  13. lstB[1] = 'The Godfather'
  14.  
  15. setA = set(combinations(lstA, 2))
  16. setB = set(combinations(lstB, 2))
  17. resultA = setA - setB
  18. resultB = setB.difference(x[::-1] for x in setA)
  19. result = resultA | resultB
  20. print(result)
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
{('Harry Potter', '1984'), ('1984', '50 Shades'), ('Harry Potter', '50 Shades'), ('Harry Potter', 'Dracula'), ('1984', 'Dracula')}
{('50 Shades', 'The Godfather'), ('Harry Potter', '50 Shades'), ('The Godfather', 'Harry Potter'), ('Harry Potter', '1984'), ('1984', 'Dracula'), ('The Godfather', '1984'), ('1984', '50 Shades'), ('50 Shades', 'Dracula'), ('Harry Potter', 'Dracula')}