Sets: Difference between revisions

From Computer Science Wiki
(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...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[file:arrows.png|right|frame|Programming basics<ref>http://www.flaticon.com/</ref>]]
[[file:arrows.png|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, 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.<ref>https://en.wikipedia.org/wiki/Set_(abstract_data_type)#Language_support</ref>
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.<ref>https://en.wikipedia.org/wiki/Set_(abstract_data_type)#Language_support</ref>


== Example ==
== Example ==
These examples are used from https://docs.python.org/3.6/tutorial/datastructures.html#sets<ref>https://docs.python.org/3.6/tutorial/datastructures.html#sets</ref> with gratitude.


<syntaxhighlight lang="python3">
<syntaxhighlight lang="python3" line>
  a = set('abracadabra')
  a = set('abracadabra')
  b = set('alacazam')
  b = set('alacazam')
Line 19: Line 20:
{'r', 'd', 'b', 'm', 'z', 'l'}
{'r', 'd', 'b', 'm', 'z', 'l'}
</syntaxhighlight>
</syntaxhighlight>
== Do you understand this?==
 
 


== Standards ==  
== Standards ==  

Latest revision as of 11:04, 20 June 2019

Programming basics[1]

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]

These examples are used from https://docs.python.org/3.6/tutorial/datastructures.html#sets[3] with gratitude.

 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'}


Standards[edit]

  • Construct algorithms using pre- defined sub-programmes, one- dimensional arrays and/or collections.


References[edit]