title: Reducing a function using dictionary
body: <p>I have two functions that are very similar:</p>
  
  <pre><code>def hier_group(self):
      if self.sku:
          return {f"{self.hierarchic}": f"${self.hierarchic}", "id": "$id", "ix": "$ix"}
      else:
          return {f"{self.hierarchic}": f"${self.hierarchic}", "ix": "$ix"}
  
  def hier_group_merge(self):
       if self.sku:
           return {f"{self.hierarchic}": f"${self.hierarchic}", "id": "$id"}
       else:
           return {f"{self.hierarchic}": f"${self.hierarchic}"}
  </code></pre>
  
  <p>I am trying to reduce into 1 function that has only one if/else.</p>
  
  <p>The only difference in both functions is <code>"ix": "$ix"</code>. </p>
  
  <p>What I am trying to do is the following:</p>
  
  <pre><code>def hier_group(self, ix=True):
         if self.sku:
             return {f"{self.hierarchic}": f"${self.hierarchic}", "id": "$id" f'{',"ix": "$ix"' if ix == True else ""}'}
         else:
             return {f"{self.hierarchic}": f"${self.hierarchic}"  f'{',"ix": "$ix"' if ix == True else ""}'}
  </code></pre>
  
  <p>But it's getting trick to return <code>, "ix": "$ix"</code>. </p>