title: f-strings formatter including for-loop or if conditions
body: <p>How can I insert <code>for</code> loops or <code>if</code> expressions inside an <strong>f-string</strong>?</p>
  
  <p>I thought initially of doing something like this for <code>if</code> expressions:</p>
  
  <pre><code>f'{a:{"s" if CONDITION else "??"}}'
  </code></pre>
  
  <p>What I would like to do though is something like:</p>
  
  <p><strong>Example 1</strong></p>
  
  <pre><code>f'{key: value\n for key, value in dict.items()}'
  </code></pre>
  
  <p><strong>result:</strong></p>
  
  <p><em>if dict = {'a': 1, 'b': 2}</em></p>
  
  <pre><code>a: 1 
  b: 2
  </code></pre>
  
  <p>or <strong>Example 2</strong></p>
  
  <pre><code>c = 'hello'
  f'{c} {name if name else "unknown"}'
  </code></pre>
  
  <p><strong>result:</strong></p>
  
  <p><em>if name exists, e.g. name = 'Mike'</em></p>
  
  <pre><code>hello Mike
  </code></pre>
  
  <p><em>otherwise</em></p>
  
  <pre><code>hello unknown
  </code></pre>
  
  <p>Can this be done and if yes how?</p>