Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A set is a collection of distinct elements, that is, each element is unique. Searching over sets is very fast and they can be used

A set is a collection of distinct elements, that is, each element is unique. Searching over sets is very fast and they can be used to find the unique items in a collection.

Cell 1:

cat_names = {"Kitty", "Garfield", "Horse"}

dog_names = {"Fido", "Odie", "Satchel"}

pet_names = cat_names|dog_names # the union of the two sets

print("pet_names = ", pet_names)

canine_names = pet_names - cat_names # the difference of the two sets

print("canine_names = ", canine_names)

Cell 2:

list1 = list(range(1,11)) # list1 is a list

print("list 1 = ", list1)

set1 = set(list1) # cast list1 as a set

print("set 1 = ", set1)

set2 = set() # empty set

for i in range(6, 16):

set2.add(i)

print("set 2 = ", set2)

set3 = set1|set2

print("set 3 = ", set3)

6 in set3

# In the code cells above that were used to perform the word count, bookcontents is a variable that stores all of

# the words in the book as a list. Enter Python code below to find the length of the list. (How many words are in the book?)

# Cast bookcontents as a set and find the length of the set. (How many unique words are in the book?)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago