create your desired list<br>>>> l = ['a', 'a', 'b', 'b'] <br><br>do a permutation and take unique values<br>>> import itertools<br>>> set(itertools.permutations(l))<br><br>
HTH<br><br><div class="gmail_quote">On Fri, Dec 18, 2009 at 11:24 AM, Michael Morrissey <span dir="ltr"><<a href="mailto:gdoghomes@gmail.com">gdoghomes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>I'm just a philosophy teacher, and I don't know much about mathematics or computers. I'm writing a python program (not the best language for this topic, but it is what I know), and I need to solve a problem which requires more knowledge than I have. I'm hoping you can help me. =)</div>
<div><br></div><div>I'm looking for an efficient way to create all the unique, non-duplicated permutations of a list (I believe these are called "necklaces" in combinatorics). I need to do this without actually generating every possible permutation (which includes all the duplicates).</div>
<div><br></div><div>For example:</div><div><br></div><div>List = [a,a,b,b]</div><div><br></div><div>My output would be something like:</div><div><br></div><div>a,a,b,b</div><div>a,b,a,b</div><div>a,b,b,a</div><div>b,a,a,b</div>
<div>b,a,b,a</div><div>b,b,a,a</div><div><br></div><div>Importantly, you'll see that these are only generated once. There are four permutations which can be generated from the list which all look like (a,a,b,b), but I only want to generate this output a single time.</div>
<div><br></div><div>My problem is large enough that I can't feasibly generate all the permutations (60! I think) and eliminate the duplicates from there, but I could feasibly generate the unique ones (a much small search space), especially if I use an efficient algorithm (I'm sorry to focus so much on efficiency, but it matters).</div>
<div><br></div><div>What is the best way to do this? If you don't know how it would work in Python, can you explain in psuedocode? As I said, I'm not very smart about these things, so treat like a child to the topic (because I am a child to the topic, an interested child!).</div>
<div><br></div><div>Oh, and thanks for this mailing/reading list! I spend countless hours browsing and reading other people's code. It is a lot of fun =).</div><div><br></div><div><br></div><div><br></div><div><br></div>
<div>Sincerely,</div><div>Michael</div><font color="#888888"><div><br></div><div><br></div><div><br></div>
</font><br>_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br>