The 2**n different lists that you are seeking have a direct association to the binary representation of the integers 0 through (2**n)-1.<div><br>You can use this fact and the &quot;repeated division method&quot; for converting numbers between different bases to generate these lists and form the desired list of lists:
<br><br></div><div><div>def bit_list_maker(n):</div><div>&nbsp;&nbsp; &nbsp;x = 2**n</div><div>&nbsp;&nbsp; &nbsp;solution_set = []</div><div>&nbsp;&nbsp; &nbsp;for i in range(x):</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this_answer = []
</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while i&gt;0:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this_answer.append(i%2)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i=i/2</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while len(this_answer)&lt;n:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this_answer.append(0)
</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this_answer.reverse()</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;solution_set.append(this_answer)</div><div>&nbsp;&nbsp; &nbsp;return solution_set</div><b><br></b></div><div><div>Another fun way to do it is to build up the lists recursively.&nbsp; The possibilities for n bits can be built from the possibilities for n-1 bits by adding a 1 and a 0 to each possibility (ending up with twice as many elements):
<br></div><div><div><br>def recursive_bit_list(n):</div><div>&nbsp;&nbsp; &nbsp;if n==1:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return [[0],[1]]</div><div>&nbsp;&nbsp; &nbsp;else:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; map(lambda x: x+[1], recursive_bit_list(n-1))</div><br>Hope this helps!<br><br>-Hugh<br><br>&nbsp;</div></div>
<div><div><span class="gmail_quote">On 6/14/07, <b class="gmail_sendername">Andy Cheesman</b> &lt;<a href="mailto:Andy.cheesman@bristol.ac.uk" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Andy.cheesman@bristol.ac.uk
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi people<br><br>I am trying to generate an array of all possible combinations of 1, and<br>zeros (see example data) for a rather nice Kinetic mote Carlo program<br>which I am writing python. So far, I&#39;ve been working out for
<br>combinations for 4 or less species by hand as it is quick! but I am<br>looking to automate the process so I can compute combinations for large<br>&nbsp;&nbsp;numbers of possible species.<br>I could automate the generation of the array by the use of multiple
<br>loops but that doesn&#39;t seem rather pythonic. I was wondering if anyone<br>had any sensible suggestions or pointers for efficient mechanisms for<br>the array.<br><br>Many Thanks<br>Andy<br><br>Example Data<br>3 species
<br>array([[1, 1, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 1, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 0, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 1, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 0, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 1, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 0, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 0, 0]])<br>4 species<br>array([[1, 1, 1, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 1, 1, 1],
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 0, 1, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 1, 0, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 1, 1, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 1, 0, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 0, 1, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 0, 0, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 1, 1, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 1, 0, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 0, 1, 1],<br>



&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [1, 0, 0, 0],
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 1, 0, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 0, 1, 0],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 0, 0, 1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0, 0, 0, 0]])<br><br>_______________________________________________<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">



Tutor@python.org
</a><br><a href="http://mail.python.org/mailman" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://mail.python.org/mailman</a>/listinfo/tutor<br></blockquote></div><br></div>