title: Python - Get sublist of list if condition is met
body: <p>I have some lists of objects I'm using in different functions for my project but first I must parse them to make sure I'm using the correct ones. I'm doing this in my function below. Currently what I'm using is a conditional check since depending on the location of the objects in the list, they might be in a different structure. I'm curious if there is anyway to consolidate the parse() function and only search in the sub list if the conditional statement is still met.</p>
  
  <pre><code>items = [A,[B,C,D]]
  
  def parse(type):
      if type == 0:
          # returns A
          return items[0]
      elif type == 1:
          # returns B, C, or D
          return items[1][random.randint(0,2)]
  </code></pre>
  
  <p>to something like this...</p>
  
  <pre><code>items = [A,[B,C,D]]
  
  def parse(type):
      return items[type] if type == 1: [random.randint(0,2)]
  </code></pre>