Computer Science 1026A/B Lecture Notes - Lecture 10: Separating Set, Empty Set

107 views11 pages
terubarenuka and 39895 others unlocked
COMPSCI 1026A/B Full Course Notes
26
COMPSCI 1026A/B Full Course Notes
Verified Note
26 documents

Document Summary

A set is an unordered collection of unique elements. Elements are unordered: elements in the set do not have a position or index. Elements are unique: no elements in the set share the same value. A set can be created using the set() function, which accepts a sequence-type iterable object (list, tuple, string, etc. ) whose elements are inserted into the set. A set literal can be written using curly braces { } with commas separating set elements. Note that an empty set can only be created using set(). # create a set using the set() function. nums1 = set([1, 2, 3]) # create a set using a set literal. nums2 = { 7, 8, 9 } # print the contents of the sets. print(nums1) print(nums2) Because the elements of a set are unordered and have no meaningful position in the collection, the index operator is not valid.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents