Oscar wrote:
>>> def uniquecombinations(h, m):
>>>     for ha in submultisets(h, len(h)//2):
>>>         hb = list(h)
>>>         for c in ha:
>>>             hb.remove(c)
>>>         yield [m[0] + a for a in ha] + [m[1] + b for b in hb]
>>>
>>> h = ['A', 'A', 'B', 'B']
>>> m = ['a', 'b']
>>>
>>> for x in uniquecombinations(h, m):
>>>     print(x)
>>> '''
>>>
>>> Output:
>>> ['aB', 'aB', 'bA', 'bA']
>>> ['aA', 'aB', 'bA', 'bB']
>>> ['aA', 'aA', 'bB', 'bB']

On 3 October 2012 21:15, Steen Lysgaard <boxeakast...@gmail.com> wrote:
> Hi,
>
> thanks for your interest. Sorry for not being completely clear, yes
> the length of m will always be half of the length of h.
>
> /Steen

Then you can make the uniquecombinations function recursive. First
find the elements that go with 'a' then from the remaining elements
find those that go with 'b', then 'c' and so on.

Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to