bsym.permutations

class bsym.permutations.SupportsRichComparison(*args, **kwargs)[source]

Bases: Protocol

bsym.permutations.flatten_list(this_list: list[list]) list[source]
bsym.permutations.number_of_unique_permutations(seq: list) int[source]

Calculate the number of unique permutations of a sequence seq.

Parameters:

seq (list) – list of items.

Returns:

The number of unique permutations of seq

Return type:

int

bsym.permutations.unique_permutations(seq: Sequence[T]) Generator[tuple[T, ...], None, None][source]

Yield only unique permutations of seq in an efficient way.

A python implementation of Knuth’s “Algorithm L”, also known from the std::next_permutation function of C++, and as the permutation algorithm of Narayana Pandita.

see http://stackoverflow.com/questions/12836385/how-can-i-interleave-or-create-unique-permutations-of-two-stings-without-recurs/12837695