title: Good way of dividing a list of lists in two parts, conditional to the values in the inner list
body: <p>The objective is to start with the following:</p>
  
  <pre><code>budget = 100
  projects = [('B', 60), ('A', 35), ('F', 35), ('G', 35), ('C', 20), ('E', 20), ('D', 10)]
  </code></pre>
  
  <p>And achieve <code>projects=[('B', 60), ('A', 35)]</code> and <code>remainingBudget =5</code>. </p>
  
  <p>As a JS programmer, I have gotten the following to work by some means:</p>
  
  <pre><code>def findProjectsThatFitTheBudget(budget, projects):
      # find the most expensive projects that fit the given budget, and note the budget that remains after allocations
      remainingBudget = budget
  
      def shoulIncludeProject(name, cost):
          nonlocal remainingBudget
          if(cost &lt;= remainingBudget):
              remainingBudget -= cost
              return True
          return False
      projects = list(
          takewhile(lambda project: shoulIncludeProject(project[0], project[1]), projects))
  
      # we now have the projects we are working with, and also the budget that remains unallocated
  </code></pre>
  
  <p>I wonder what is the most pythonic way of refactoring this? I was stuck with the following at the least:</p>
  
  <ol>
  <li>How do I write a simple lambda instead of an external def</li>
  <li>How do I do destructuring in the arguments to the lambda</li>
  <li>How do I use <code>and</code> in a short-circuit way with <code>budget=-cost</code></li>
  </ol>
  
  <p>A beautiful solution could have been:</p>
  
  <pre><code>projects = list(
      takewhile(lambda name, cost: cost&lt;= budget and budget=-cost, projects))
  </code></pre>
  
  <p>using <code>and</code> in the <code>short-circuit</code> way.</p>