Skip to content
CodeItRaw
Hashing

Lesson 2/5

Because a set drops repeats on its own, finding how many different values a list has is one line: put them all in a set and look at its size.

len(set(values)) # how many distinct values
len(set(values)) < len(values) # is there any repeat?

The second line is another answer to "is there a repeat?": if there are fewer distinct values than elements, something repeated. It is short but reads the whole list; the loop version can stop at the first repeat.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.

  1. 01

    How Many Different Values?

    Code reading · Break the Code

  2. 02

    Twin Packet

    Code Duel

  3. 03

    Sign-up Audit

    Function

If you would rather not wait for the order, every problem is open without locks: Problem list