How do I recursively increment the first value in a list and append to a nested list in python?
<p>I wrote a function called <code>change</code> which takes in an <code>int</code> and a list of coins. </p>

<p>It recursively checks what the least amount of coins are needed to create that amount and returns this number. Now I am trying to modify this function to take the same input but instead return a list with the number of coins and a list of coins used.</p>

<pre><code>def change(amount, coins):
    if amount == 0:
        return 0
    if coins == []:
        return float("inf")
    if coins[0] &gt; amount:
        return change(amount, coins[1:])
    use_it = 1+change(amount-coins[0], coins)
    lose_it = change(amount, coins[1:])
    return min(use_it, lose_it)
</code></pre>

<p>I began modifying this code but I'm not sure how to manipulate the return value given that it's a list:</p>

<pre><code>def giveChange(amount, coins):
    if amount == 0:
        return [0, []]
    if coins == []:
        return [float("inf"), []]
    if coins[0] &gt; amount:
        return giveChange(amount, coins[1:])
    use_it = 1 + giveChange(amount-coins[0], coins)
    lose_it = giveChange(amount, coins[1:])
    listOfCoins = 
    return [min(use_it, lose_it), listOfCoins]
</code></pre>

<p>I have this so far but my use_it line is wrong because the function now returns a list. Could I simply do this:</p>

<pre><code>use_it = 1 + giveChange(amount-coins[0], coins)[0]
</code></pre>

<p>I am not sure how to build up the list of coins so that I can return it with the amount of coins at the end.</p>