From Computer Science Wiki
Jump to: navigation, search
Programming basics[1]

In computer science, a set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.[2]


These examples are used from[3] with gratitude.

 1  a = set('abracadabra')
 2  b = set('alacazam')
 3  a                                  # unique letters in a
 4 {'a', 'r', 'b', 'c', 'd'}
 5  a - b                              # letters in a but not in b
 6 {'r', 'd', 'b'}
 7  a | b                              # letters in a or b or both
 8 {'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
 9  a & b                              # letters in both a and b
10 {'a', 'c'}
11  a ^ b                              # letters in a or b but not both
12 {'r', 'd', 'b', 'm', 'z', 'l'}

Do you understand this?


  • ConstructDevelop information in a diagrammatic or logical form. algorithms using pre- defined sub-programmes, one- dimensional arrays and/or collections.