# 有三个显示器
outs = ['e1', 'h1', 'e2']
# 需要得到的数组
[['e1'],
['h1'],
['e2'],
['e1', 'h1'],
['e1', 'e2'],
['h1', 'e1'],
['h1', 'e2'],
['e2', 'e1'],
['e2', 'h1'],
['e1', 'h1', 'e2'],
['e1', 'e2', 'h1'],
['h1', 'e1', 'e2'],
['h1', 'e2', 'e1'],
['e2', 'e1', 'h1'],
['e2', 'h1', 'e1']]
## 思路:为每个长度为i的数组中,加入还不存在的元素,得到长度为i+1的数组
choices = []
pre = [[]] # 每个pre中,记录了长度相同的组合
for _ in outs:
new = []
for p in pre:
for o in outs:
if not o in p:
# 加入不存在的元素,得到新组合,加入new数组中
new.append(p + [o])
pre = new
choices.extend(new)
print(choices)
最终拼接成类似这样的命令:
xrandr --output e1 --auto --output h1 --auto --right-of e1
xrandr --output e1 --auto --output h1 --auto --same-as e1