<div class="gmail_quote">On 3 October 2012 15:26, Steen Lysgaard <span dir="ltr"><<a href="mailto:boxeakasteen@gmail.com" target="_blank">boxeakasteen@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class="gmail_quote">Hi,<br><br>I am looking for a clever way to compute all combinations of two lists. Look at this example:<br><br>
h = ['A','A','B','B']<br>m = ['a','b']<br><br>the resulting combinations should be of the same length as h and each element in m can be used twice. The sought after result using h and m from above is:<br>
<br>[['aA', 'aA', 'bB', 'bB'],<br> ['aA', 'aB', 'bA', 'bB'],<br> ['aB', 'aB', 'bA', 'bA']]<br><br>(the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] and ['aA', 'bB', 'aA', 'bB'] are considered the same)<br>
<br>This is achieved by the code below, this however needs to go through all possible combinations (faculty of len(h)) and rule out duplicates as they occur and this is too much if for example len(h) is 16.<br><br>Can anyone guide me to a better solution?</blockquote>
<div> </div>
<div>What lengths can the two lists be?</div><div><br></div><div>Is len(h) === 2*len(m), or it it just this time?</div><div><br></div><div>Depending on your answer this could be easy or hard ;)</div></div>