Casepy package

casepy (instant methods)

instant_method.all_permutations(in_number_of_select: int) list

Return all permutations of the list.

Parameters:
  • in_list (list) – The list to be permuted.

  • in_number_of_select (int) – The number of elements to be selected.

Returns:

All permutations of the list.

Return type:

list

Examples

>>> result = all_permutation([1, 2, 3, 3], 2)
>>> print(result)
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2], [3, 3]]
instant_method.n_th_permutation(in_list: list, in_number_of_select: int) list

Return the n-th permutation of the list.

Parameters:
  • in_iterator (int) – Iterator n indicates the n-th permutation.

  • in_list (list) – The list to be permuted.

  • in_number_of_select (int) – The number of elements to be selected.

Returns:

The n-th permutation of the list.

Return type:

list

Examples

>>> result = n_th_permutation(3, [1, 2, 3, 3], 2)
>>> print(result)
[2, 3]
instant_method.n_to_m_th_permutations(in_m_iterator: int, in_list: list, in_number_of_select: int) list

Return list of permutations from n-th to m-th.

Parameters:
  • in_n_iterator (int) – Iterator n indicates the n-th permutation.

  • in_m_iterator (int) – Iterator m indicates the m-th permutation.

  • in_list (list) – The list to be permuted.

  • in_number_of_select (int) – The number of elements to be selected.

Returns:

List of permutation from n-th to m-th.

Return type:

list

Examples

>>> result = n_to_m_th_permutation(2, 4, [1, 2, 3, 3], 2)
>>> print(result)
[[2,1],[2,3],[3,1]]
instant_method.all_combinations(in_number_of_select: int) list

Return all combinations of the list.

Parameters:
  • in_list (list) – The list to be combined.

  • in_number_of_select (int) – The number of elements to be selected.

Returns:

All combinations of the list.

Return type:

list

Examples

>>> result = all_combination([1, 2, 3, 3], 2)
>>> print(result)
[[1, 2], [1, 3], [2, 3]]
instant_method.n_th_combination(in_list: list, in_number_of_select: int) list

Return the n-th combination of the list.

Parameters:
  • in_iterator (int) – Iterator n indicates the n-th combination.

  • in_list (list) – The list to be combined.

  • in_number_of_select (int) – The number of elements to be selected.

Returns:

The n-th combination of the list.

Return type:

list

Examples

>>> result = n_th_combination(2, [1, 2, 3, 3], 2)
>>> print(result)
[2, 3]
instant_method.n_to_m_th_combinations(in_m_iterator: int, in_list: list, in_number_of_select: int) list

Return list of combinations from n-th to m-th.

Parameters:
  • in_n_iterator (int) – Iterator n indicates the n-th combination.

  • in_m_iterator (int) – Iterator m indicates the m-th combination.

  • in_list (list) – The list to be combined.

  • in_number_of_select (int) – The number of elements to be selected.

Returns:

List of combination from n-th to m-th.

Return type:

list

Examples

>>> result = n_to_m_th_combinations(2, 4, [1, 2, 3, 3], 2)
>>> print(result)
[[2, 3], [3, 1], [3, 2]]

casepy.permutation_generator

class casepy.PermutationGenerator

Bases: object

PermutationGenerator is designed to generates all possible permutations of elements in a list with a given number of selections. The permuation is generated by a given iterator number and it is the n-th permutation of the all possible permutations. As default, the n-th permutation is generated by the lexicographic order. But, if the priority of the elements is given, the permutation is generated by the given priority.

The elements can be duplicated in the list.

all_cases() list

Return all possible permutations from a set parameters.

Returns:

All possible permutations.

Return type:

list

n_th_case(in_iterator: int) list

Return the n-th permutation.

Parameters:

in_iterator (int) – The iterator that indicates the n-th permutation.

Returns:

The n-th permutation.

Return type:

list

n_to_m_th_cases(in_n_iterator: int, in_m_iterator: int) list

Return the n-th to m-th permutations.

Parameters:
  • in_n_iterator (int) – The iterator that indicates the n-th permutation.

  • in_m_iterator (int) – The iterator that indicates the m-th permutation.

Returns:

The n-th to m-th permutations.

Return type:

list

set_parameters(element_list: list, in_number_of_selection: int)

Initialize the PermutationGenerator with the given number of selections and the element list.

Parameters:
  • in_number_of_selection (int) – The number of selections.

  • element_list (list) – The list of elements.

casepy.combination_generator

class casepy.CombinationGenerator

Bases: object

CombinationGenerator is designed to generates all possible combinations of elements in a list with a given number of selections. The combination is generated by a given iterator number and it is the n-th combination of the all possible combinations. As default, the n-th combination is generated by the lexicographic order. But, if the priority of the elements is given, the combination is generated by the given priority.

The elements can be duplicated in the list.

all_cases()

Return all possible combinations of the list.

Returns:

All possible combinations of the list.

Return type:

list

n_th_case(in_iterator: int) list
n_to_m_th_cases(in_n_iterator: int, in_m_iterator: int) list
set_parameters(in_number_of_selection: int, element_list: list)

Initialize the CombinationGenerator with the given number of selections and the element list.

Parameters:
  • in_number_of_selection (int) – The number of selections.

  • element_list (list) – The list of elements.