[英]how to get all possible results in list that equal or smaller than 2 but equal or greater than 1?
可能不是最好的方法,但你可以這樣做:
from itertools import permutations
s = [list(t) for t in {p for p in permutations([1, 1, 1, 2, 2, 2], 3)}]
print(s)
Output:
[[1, 2, 1], [2, 1, 1], [2, 2, 2], [1, 1, 2], [1, 2, 2], [2, 1, 2], [2, 2, 1], [1, 1, 1]]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.