title: How to create an indexable and sliceable enum with string values in Python?
body: <p>I've got a file like this:</p>
  
  <pre><code>class Level(Enum):
      prerequisite_level: Optional["Level"]
      dependent_level: Optional["Level"]
      lower_priority_levels: List["Level"]
      greater_priority_levels: List["Level"]
  
      DATA_CHECK = "data check"
      DESIGN_CHECK = "design check"
      ALERT = "alert"
  </code></pre>
  
  <p>The enum values are in a specific order, and based on each of those levels I need to be able to get the previous one, the next one, and all the previous and next ones. I believe I need to be able to index the levels numerically to get these values, so I've added a constant to be able to do this:</p>
  
  <pre><code>INCREASING_PRIORITY_LEVELS: List[Level] = list(Level)
  
  for priority_level_index, threshold_level in enumerate(Level):
      if priority_level_index &gt; 0:
          threshold_level.prerequisite_level = Level[priority_level_index - 1]
      else:
          threshold_level.prerequisite_level = None
  
      if priority_level_index &lt; len(Level) - 1:
          threshold_level.dependent_level = Level[priority_level_index + 1]
      else:
          threshold_level.dependent_level = None
  
      threshold_level.lower_priority_levels = Level[:priority_level_index]
      threshold_level.greater_priority_levels = Level[priority_level_index + 1:]
  </code></pre>
  
  <p>This is clunky, and I'd like to get rid of this constant. Do I need to implement <code>__getitem__</code> or something to make this possible?</p>