title: Inline add element to list if condition
body: <p>Is there a way in python to add an object to a list if some condition?</p>
  <p>I want to do this:</p>
  <pre><code>middleware = [&quot;a&quot;,
  &quot;b&quot;,
  &quot;c&quot; if DEBUG,
  &quot;d&quot;
  ]
  </code></pre>
  <p>Such that if <code>DEBUG</code> is False, the list will be [&quot;a&quot;, &quot;b&quot;, &quot;d&quot;]</p>
  <p>My current best suggestion is this:</p>
  <pre><code>middleware = [&quot;a&quot;,
  &quot;b&quot;] + \
  ([&quot;c&quot;] if DEBUG else []) + \
  [&quot;d&quot;
  ]
  </code></pre>
  <p>which doesn't look very intuitive</p>