Create and test a Set class to represent a classical set. Your sets should support the

Chapter 11, Problem 19

(choose chapter or problem)

Get Unlimited Answers
QUESTION:

Create and test a Set class to represent a classical set. Your sets should support the following methods: Set (elements) Creates a set (elements is the initial list of items in the set). addElement (x) Adds x to the set. deleteElement (x) Removes x from the set, if present. If x is not in the set, the set is left unchanged. member (x) Returns true if x is in the set and false otherwise. intersection( set2) Returns a new set containing just those elements that are common to this set and set2. union( set2) Returns a new set containing all of elements that are in this set, set2, or both. subtract ( set2) Returns a new set containing all the elements of this set that are not in set2. By the way, sets are so useful that Python actually has a built-in set datatype. While you may want to investigate Python's set, you should not use it here. The point of this exercise is to help you develop your skills in algorithm development using lists and dictionaries.

Questions & Answers

QUESTION:

Create and test a Set class to represent a classical set. Your sets should support the following methods: Set (elements) Creates a set (elements is the initial list of items in the set). addElement (x) Adds x to the set. deleteElement (x) Removes x from the set, if present. If x is not in the set, the set is left unchanged. member (x) Returns true if x is in the set and false otherwise. intersection( set2) Returns a new set containing just those elements that are common to this set and set2. union( set2) Returns a new set containing all of elements that are in this set, set2, or both. subtract ( set2) Returns a new set containing all the elements of this set that are not in set2. By the way, sets are so useful that Python actually has a built-in set datatype. While you may want to investigate Python's set, you should not use it here. The point of this exercise is to help you develop your skills in algorithm development using lists and dictionaries.

ANSWER:

Step 1 of 3

The classes in Python are defined using the keyword “Class” followed by the name of the class. It contains various methods to perform operations. The objective of the question is to design a class named Set.

Add to cart


Study Tools You Might Need

Not The Solution You Need? Search for Your Answer Here:

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back