ML-learning-path

Self learning guide for machine learning

View the Project on GitHub elephantscale/ML-learning-path

Python Data Structures - Set

Index/ Python


Objective

Learn the set data structures in python

Reference

Essentials

Checklist

After completing the exercises below, you should be comfortable with

Exercises

Difficulty Level

★☆☆ - Easy
★★☆ - Medium
★★★ - Challenging
★★★★ - Bonus

A - Creating Sets

A1 - Create a set a = {10,20,30,40,50} (★☆☆)

We will use this list for exercises below

A2 - Add 60 to set (★☆☆)

Print out the set and notice the order

B - Searching

B1 - Searching a Set (★☆☆)

Create a Set with 10 random numbers between 1 to 100.

Now create another 10 random numbers, and check if these numbers are in the set.

B2 - De-duplicate (★★☆)

De-duplicate this list of numbers.

a = [1, 5, 2, 3, 1, 4, 3, 5]

The output should be (in no order)

1, 5, 2, 3, 4

B3 - De-duplicate (★★☆)

Print unique words from this paragraph.

str = "it was the best of times \
it was the worst of times \
it was the age of wisdom \
it was the age of foolishness \
it was the epoch of belief \
it was the epoch of incredulity \
it was the season of light \
it was the season of darkness \
it was the spring of hope \
it was the winter of despair"

words = str.split()
# list of words. 
# Now find the unique words

More Exercises