Set operations on unique letters from two words : Set Declaration « Data Structure « Python






Set operations on unique letters from two words

Set operations on unique letters from two words

a = set('abracadabra')
b = set('alacazam')
print a                                  # unique letters in a
set(['a', 'r', 'b', 'c', 'd'])
print a - b                              # letters in a but not in b

print a | b                              # letters in either a or b

print a & b                              # letters in both a and b

print a ^ b                              # letters in a or b but not both

           
       








Related examples in the same category

1.Sets: A set is an unordered collection with no duplicate elementsSets: A set is an unordered collection with no duplicate elements