{'apple', 'banana', 'kiwi', 'pear'}
mutable objectunordered datastructureset{})len(), min(), max(), sum().add(value) adds an value to the set.remove(value) removes an value from the set (throws error if no matching value found).discard(value) removes an value from the set (no error if no matching value found)Since items in a set are not ordered, not sequential, there’s no index in sets.
Items in a set are not ordered, and cannot repeat.
{'apple', 'banana', 'kiwi', 'pear'}
.add(value) adds an item to the set, if the value is already there, nothing happens (it changes the set).union(other_set) returns a new set containing all unique elements from both sets – can also use |.intersection(other_set) returns a new set containing only the elements common to both sets – can also use &.difference(other_set) returns a new set containing elements present in one set but not in other_set – can also use -Two sections of a course each have a roster, stored as a list of student usernames. The lists may contain duplicates because of data-entry mistakes. Create a compare_roster.py file and write a function compare_rosters(section_a, section_b) that takes the two lists and returns a tuple of three values:
Requirements
&, |, -, or the matching methods .intersection(), .union(), .difference()).Submit your compare_roster.py solution to gradescope
Test cases:
assert compare_rosters(["ana", "ben", "cai", "ana"], ["ben", "dev", "cai"]) == ({"ben", "cai"}, {"ana"}, 4)
assert compare_rosters(["x", "y"], ["z"]) == (set(), {"x", "y"}, 3)
assert compare_rosters([], ["amy", "amy"]) == (set(), set(), 1)
assert compare_rosters([], []) == (set(), set(), 0)
assert compare_rosters(["p", "q"], ["q", "p"]) == ({"p", "q"}, set(), 2)
print("All tests passed!")Submit your compare_roster.py solution to gradescope