title: How to use await in a python lambda
body: <p>I'm trying to do something like this:</p>
  
  <pre><code>mylist.sort(key=lambda x: await somefunction(x))
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>SyntaxError: 'await' outside async function
  </code></pre>
  
  <p>Which makes sense because the lambda is not async.</p>
  
  <p>I tried to use <code>async lambda x: ...</code> but that throws  a <code>SyntaxError: invalid syntax</code>.</p>
  
  <p><a href="https://www.python.org/dev/peps/pep-0492/#async-lambda-functions" rel="noreferrer">Pep 492</a> states:</p>
  
  <blockquote>
    <p>Syntax for asynchronous lambda functions could be provided, but this construct is outside of the scope of this PEP.</p>
  </blockquote>
  
  <p>But I could not find out if that syntax was implemented in CPython.</p>
  
  <p>Is there a way to declare an async lambda, or to use an async function for sorting a list?</p>