Sets: Difference between revisions
Mr. MacKenty (talk | contribs) (Created page with "right|frame|Programming basics<ref>http://www.flaticon.com/</ref> In computer science, a set is an abstract data type that can store certain values, witho...") |
Mr. MacKenty (talk | contribs) |
||
Line 5: | Line 5: | ||
== Example == | == Example == | ||
<syntaxhighlight lang="python3"> | <syntaxhighlight lang="python3" line> | ||
a = set('abracadabra') | a = set('abracadabra') | ||
b = set('alacazam') | b = set('alacazam') | ||
Line 19: | Line 19: | ||
{'r', 'd', 'b', 'm', 'z', 'l'} | {'r', 'd', 'b', 'm', 'z', 'l'} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Do you understand this?== | == Do you understand this?== | ||
Revision as of 06:09, 8 August 2017
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]
Example[edit]
a = set('abracadabra')
b = set('alacazam')
a # unique letters in a
{'a', 'r', 'b', 'c', 'd'}
a - b # letters in a but not in b
{'r', 'd', 'b'}
a | b # letters in a or b or both
{'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
a & b # letters in both a and b
{'a', 'c'}
a ^ b # letters in a or b but not both
{'r', 'd', 'b', 'm', 'z', 'l'}
Do you understand this?[edit]
Standards[edit]
- Construct algorithms using pre- defined sub-programmes, one- dimensional arrays and/or collections.