Python 3D Academyবাংলা

Sets in Python

Chapter 10: Sets

4 short lessons, with 3D animations, quizzes and coding tasks.

The lessons

  1. Making sets

    A set holds each value only once, keeps no order, and answers in very quickly.

  2. Changing a set

    add puts a value in (if it isn't there already), remove takes it out and complains if it's missing, and discard takes it out quietly.

  3. Combining sets: | & - ^

    Four operators combine two sets into a new set, choosing from the left circle, the right circle, or the overlap.

  4. Sets in practice

    Compare whole sets with == and <=, find repeats by comparing len(set(x)) with len(x), and pair a seen set with a list when the order matters.