У меня есть список (скажем, 6 элементов для простоты)
L = [0, 1, 2, 3, 4, 5]
и я хочу поместить его в пары в ВСЕ возможных способах. Я показываю некоторые конфигурации:
[(0, 1), (2, 3), (4, 5)]
[(0, 1), (2, 4), (3, 5)]
[(0, 1), (2, 5), (3, 4)]
и т.д.
Здесь (a, b) = (b, a)
и порядок пар не важен, т.е.
[(0, 1), (2, 3), (4, 5)] = [(0, 1), (4, 5), (2, 3)]
Общее количество таких конфигураций 1*3*5*...*(N-1)
, где N
- длина моего списка.
Как я могу написать генератор в Python, который дает мне все возможные конфигурации для произвольного N
?