Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE CODE IN PYTHON!! THANK YOU!!! Activity 2: Python Sets - Demonstration o Sets are data structures, similar to lists or dictionaries. o Sets are
PLEASE CODE IN PYTHON!! THANK YOU!!!
Activity 2: Python Sets - Demonstration o Sets are data structures, similar to lists or dictionaries. o Sets are created using {} or with the set function. Oxyz = set(['lebron', 'russell', 'steph']). // I RECOMMEND USING THIS APPROACH OOR o myset = {"apple", "banana", "cherry"} You can use the len() function to determine the length of a Set o They are UNORDERED which means they can't be indexed o They CANNOT contain duplicates O Sets can be searched through much faster than the other 3 Data Collection objects o Use add() to add an item to the Set o Use remove() to delete a specific element o Use pop() to remove a random element o Use the union method or operator to combine two sets o union1 = set1.union(set 2) where 'set2' is one set and 'setl' is another set //method OR o new_Set = seti | set 2. I/operator **Professional way is to use this approach o Use the intersection method or operator to return elements that appear in BOTH sets intersection1 = set1.intersection(set2). //method OR Intersection 1 = seti & set2. //operator ** Professional way is to use this approach o Conversely, you can find any items that DO NOT appear in BOTH sets o difference2 = set2.difference(set1). //method O OR o diff1=set1 - set2 //operator ** Professional way is to use this approach O LAST, find items that appear in the first file or the second file but do not appear in both files using difference () method or operator o sym_diff = set1.symmetric_difference(set2)//method OR o C = set1 ^ set2 //operator ** Professional way is to use this approach O O 0 oStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started