Non decreasing sequences
<p>I am trying to write a simple python script that will find all the non-decreasing sequences made up of positive integers summing to 7. My code does not seem to work as it's supposed to no matter what I try. Here's what I have</p>

<pre><code>components = [1,2,3,4,5,6,7]

ans = []

def sumSeq(seq):
    sumA = 0
    for i in seq:
        sumA += i
    return sumA

def findSeq(seq):
    for x in components:
        if (x &lt; seq[-1]):
            continue

        newSeq = seq
        newSeq.append(x)
        sumA = sumSeq(newSeq)

        if (sumA &gt; 7):
            continue

        if (sumA == 7):
            ans.append(newSeq)

        findSeq(newSeq)

findSeq([0])

print ans
</code></pre>

<pre><code>newSeq = seq
</code></pre>

<p>This line doesn't do what you think it does. Specifically, it does <em>not</em> create a new list. It merely creates a new name that refers to the existing list.  Try:</p>

<pre><code>newSeq = seq[:]
</code></pre>

python sequence