title: How can I rewrite this Python operation so it doesn't hang my system?
body: <p>Beginner here, looked for an answer, but can't find one.</p>
  
  <p>I know (or rather suspect) that part of the problem with the following code is how big the list of combinations gets.  </p>
  
  <p>(Maybe too, the last line seems like an error, in that, if I just run 'print ...' rather than 'comb += ...' it runs quickly and quits.  Would 'append' be more graceful?)  </p>
  
  <p>I'm not 100% sure if the system hang is due to disk I/O (swapping?), CPU use, or memory... running it under Windows seems to result in a rather large disk I/O by 'System', while under Linux, top was showing high CPU and memory use before it was killed.  In both cases though, the rest of the system was unusable while this operation was going (tried it in the Python interpreter directly, as well as in PyCharm).</p>
  
  <p>So two part question:  1) is there some 'safe' way to test code like this that won't affect the rest of the system negatively, and 2) for this specific example, how should I rewrite it?</p>
  
  <p>Trying this code (which I do not recommend!):</p>
  
  <pre><code>from itertools import combinations_with_replacement as cwr
  comb = []
  iterable = [1,2,3,4]
  for x in xrange(4,100):
    comb += cwr(iterable, x)
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>EDIT: Should have specified, but it is python2.7 code here as well (guess the xrange makes it obvious it's not 3 anyways).  The Windows machine that's hanging has 4 GB of RAM, but it looks like the hang is on disk I/O.  The original problem I was (and still am) working on was a question at codewars.com, about how many ways to make change given a list of possible coins and an amount to make.  The solution I'd come up with worked for small amounts, and not big ones.  Obviously, I need to come up with a better algorithm to solve that problem... so this is non-essential code,  certainly.  However, I would like to know if there's something I can do to set the programming environment so that bugs in my code don't propagate and choke my system this way.</p>
  
  <p>FURTHER EDIT:
  I was working on the problem again tonight, and realized that I didn't need to append to a master list (as some of you hinted to me in the comments), but just work on the subset that was collected.  I hadn't really given enough of the code to make that obvious, but my key problem here was the line:</p>
  
  <p>comb += cwr(iterable, x)</p>
  
  <p>which should have been</p>
  
  <p>comb = cwr(iterable, x)</p>