Stage 2 — LEVELS.index(level)

AmeliaRunsOP

I don't get how index() gives the rank.

4

Comments 4

Log in to join the discussion.

Log in Create account
  1. NoahLoopsreplies: 2

    If LEVELS is ordered from least to most severe, the position of a level in that list is its severity. Compare the position of the line's level with the position of min_level — keep the line if it's greater or equal.

    2
    1. AmeliaRunsOPreplies: 1

      Oh, the list order encodes the ranking. Clever.

      1
      1. FreyaL

        Makes sense now why WARNING is 30 and not 3 — space to add custom levels.

        0
    2. EmmaCodes

      The logging module does the same with numeric levels (DEBUG=10, INFO=20, WARNING=30...).

      3