Advertisement
here2share

# set_operators.py #

May 29th, 2015
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. # set_operators.py
  2. # Demonstrating set operations on unique letters from two strings
  3.  
  4. a = set('abracadabra')
  5. b = set('alacazam')
  6.  
  7. print a             # unique letters in a               {'a', 'r', 'b', 'c', 'd'}
  8. print a - b         # letters in a but not in b         {'r', 'd', 'b'}
  9. print a | b         # letters in either a or b          {'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
  10. print a & b         # letters in both a and b           {'a', 'c'}
  11. print a ^ b         # letters in a or b but not both        {'r', 'd', 'b', 'm', 'z', 'l'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement