Skip to content

[New Concept Exercise] : sets #2296

Closed
@BethanyG

Description

@BethanyG

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, and symmetric_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 to discard (remove tosses a keyerror 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(), or map() with a set
  • set comprehensions

Concepts

  • sets
  • hashable objects
  • set comparisons
  • set operations

Prerequisites

  • basics
  • booleans
  • comparisons
  • dicts
  • lists
  • loops

Resources to refer to

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions