同じものを含む順列(ジェネレーター)

def permutations(data, result=[]):

    if not data:
        yield result

    else:
        for i in set(data):

            temp = data[:]
            temp.remove(i)

            yield from permutations(temp, result + [i])

if __name__ == '__main__':

    for i in permutations([1, 1, 1, 2, 2, 3]):
        print(i)

imabari.hateblo.jp

imabari.hateblo.jp