title: if else nested for loops using python list comprehension
body: <p>Can anyone help me figure the list comprehension way of producing following output - </p>
  
  <p>Let given list be - </p>
  
  <pre><code>results = [
      {"id":  1, "name":  "input"},
      {"name": "status", "desc": "Status"},
      {"name": "entity", "fields": [
          {"id": 101, "name": "value"},
          {"id": 102, "name": "address"}]
      }
  ]
  </code></pre>
  
  <p>And I am looking for output in the form of list. 
  The code to get the output is: </p>
  
  <pre><code>output = []
  for eachDict in results:
      if "fields" in eachDict:
          for field in eachDict["fields"]:
              output.append(eachDict["name"]+"."+field["name"])
      else:
          output.append(eachDict["name"])
  </code></pre>
  
  <p>Thus the output using above code is - </p>
  
  <pre><code>['input', 'status', 'entity.value', 'entity.address']
  </code></pre>
  
  <p>Is it possible to get similar output using if else nested for loops in list Comprehension?</p>
  
  <p>I am having trouble trying to get access to that inner for loop in if condition of list Comprehension</p>
  
  <p>My attempt - </p>
  
  <pre><code>output = [eachDict["name"]+"."+field["name"] for field in eachDict["fields"] if "fields" in eachDict else eachDict["name"] for eachDict in results]
  </code></pre>