Changes

Jump to: navigation, search

OPS435 Python Lab 4

10 bytes removed, 17:26, 14 June 2017
PART 2 - Sets
s2 ^ s3 # returns a set containing all values that both sets DO NOT share
s2.symmetric_difference(s3) # same as s2 ^ s3
</source>These powerful features can be useful and efficient. Unfortunately, lists <u>cannot</u> perform these operations, unless we have to convert the lists into sets. In order to that, you should first perform a comparison, then convert the list to a set.<br><br>There are two problems with performing the above-mentioned technique:::::*Sets are '''un-ordered''' so if the list order is important this will cause problems and remove order::::*Sets '''cannot contain duplicate values''', if the list contains any duplicate values they will be deleted.
:There are two problems with performing the above-mentioned technique:::*Sets are '''un-ordered''' so if the list order is important this will cause problems and remove order::*Sets '''cannot contain duplicate values''', if the list contains any duplicate values they will be deleted. :However, if the list does not have any of the above requirements this is a great solution to some problems.
:#To demonstrate, issue the following:<source>
l2 = [1, 2, 3, 4, 5]
13,420
edits

Navigation menu