Description
This issue describes how to implement the sets
concept exercise for the Python track.
This will be closed by #2485
Getting started
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Please also watch the following video:
Goal
The goal of this exercise is to teach the basics of the set (set type) in Python.
Learning objectives
- understand that a set is an unordered collection of distinct hashable objects
- create a
set
via constructor (set()
) and literal ({}
) - de-dupe a list of elements by converting a sequence type such as a list to a set type
- check for a membership of an element in a given set via
in
- set comparison functions and set comparison operators (
=<
,>=
,issubset()
,issuperset()
, etc.) - additional set operators (
union
,intersection
,difference
, andsymmetric_difference
) - add values to a given set via
add()
- remove values from a given set via
discard()
- iterate through a given set by using
for item in set
Out of scope
frozenset()
clear()
to delete all elements of a set- check the length of a given set via
len()
remove
as opposed todiscard
(remove
tosses akeyerror
if the element is not present)- all forms/variants of
update()
- remove (and use) a value from a given set via
pop()
- make shallow copy(s) of a given set via
copy()
- using additional builtins such as
sorted()
,min()
, ormap()
with a set - set comprehensions
Concepts
sets
hashable
objectsset
comparisonsset
operations
Prerequisites
basics
booleans
comparisons
dicts
lists
loops
Resources to refer to
- Set Types (Python Official Docs)
- Hashable (Python Official Docs Glossary)
- immutable (Python Official Docs Glossary)
Hints
Hints should link to the Sets
section of the Python docs tutorial: Sets
After
After, the student can explore comprehension syntax, although it will be taught in separate exercises. This would also be a good time to explore set comparisons via function &/or operator, or experimenting with the issuperset()
& issubset()
functions.
Representer
No changes required.
Analyzer
No changes required.
Implementing
Tests should be written using unittest.TestCase, and the test file named dicts_basic_test.py.
Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue.
Edits
- edited for updated naming by @yawpitch