furas

Python - set - operations

Jun 23rd, 2018
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print('\n--- data1 ---\n')
  2. data1 = set(["hi", "hello", "hallo"])
  3. print(data1)
  4. # different order {'hi', 'hallo', 'hello'}
  5.  
  6. print('\n--- data2 ---\n')
  7. data2 = set(["hello", "hey", "hello", "hey", "hello", "hey"])
  8. print(data2)
  9. # remove duplicate elements
  10. # {'hey', 'hello'}
  11.  
  12. print('\n--- data2 & data1 ---\n')
  13. print(data2 & data1)
  14. # common elements
  15. # elements which exists in both at the same time
  16. # {'hello'}
  17.  
  18. print('\n--- data2 | data1 ---\n')
  19. print(data2 | data1)
  20. # all elements from both
  21. # {'hi', 'hello', 'hallo', 'hey'}
  22.  
  23. print('\n--- data2 ^ data1 ---\n')
  24. print(data2 ^ data1)
  25. # elements which exists only in data1 or only in data2
  26. # but not in both at the same time
  27. # {'hey', 'hi', 'hallo'}
  28.  
  29. print('\n--- data2 - data1 ---\n')
  30. print(data2 - data1)
  31. # remove data1 from data2
  32. # {'hey'}
  33.  
  34. '''
  35. --- data1 ---
  36.  
  37. {'hi', 'hallo', 'hello'}
  38.  
  39. --- data2 ---
  40.  
  41. {'hey', 'hello'}
  42.  
  43. --- data2 & data1 ---
  44.  
  45. {'hello'}
  46.  
  47. --- data2 | data1 ---
  48.  
  49. {'hi', 'hello', 'hallo', 'hey'}
  50.  
  51. --- data2 ^ data1 ---
  52.  
  53. {'hey', 'hi', 'hallo'}
  54.  
  55. --- data2 - data1 ---
  56.  
  57. {'hey'}
  58. '''
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×