1樓:FRANK
我不會Python解決這個,但是我用Scala實現了:
object
Main
}結果是:
Vector(1
,1,1
)Vector(1
,1,3
)Vector(1
,1,5
)Vector(1
,1,7
)Vector(1
,3,3
)Vector(1
,3,5
)Vector(1
,3,7
)Vector(1
,5,5
)Vector(1
,5,7
)Vector(1
,7,7
)Vector(3
,3,3
)Vector(3
,3,5
)Vector(3
,3,7
)Vector(3
,5,5
)Vector(3
,5,7
)Vector(3
,7,7
)Vector(5
,5,5
)Vector(5
,5,7
)Vector(5
,7,7
)Vector(7
,7,7
)所以是:
("(1, 1, 1)(1, 1, 3)(1, 1, 5)(1, 1, 7)(1, 3, 3)(1, 3, 5)\n"
+"(1, 3, 7)(1, 5, 5)(1, 5, 7)(1, 7, 7)(3, 3, 3)(3, 3, 5)\n"
+"(3, 3, 7)(3, 5, 5)(3, 5, 7)(3, 7, 7)(5, 5, 5)(5, 5, 7)\n"
+"(5, 7, 7)(7, 7, 7)\n")
2樓:PythonOffice
#定義列表元素分組函式,便於將6個數分成一組deflist_of_groups
(init_list
,children_list_len
):list_of_groups
=zip(*
(iter
(init_list
),)*
children_list_len
)end_list=[
list(i
)foriin
list_of_groups
]count
=len
(init_list)%
children_list_len
end_list.(
init_list[-
count
:])if
count!=0
else
end_list
return
end_list
#生成目標列表,並列印
from
itertools
import
permutations
list1=[
iforiin
list
(permutations([1
,3,5
,7],3
))]data=
fori
inlist1
:combine=""
forjini
:combine
+=str(j
)data.(
combine
)result
=list_of_groups
(data,6
)#呼叫列表元素分組函式
fori
inresult
(" "
.join(i
))結果圖,滿足要求嗎O(∩_∩)O~?
3樓:喳 小銘
>>>from
itertools
import
permutations
>>>l=
[ifori
inlist
(permutations([1
,3,5
,7],3
))]>>>
fori
inrange
(len(l
)):...ifi
%6==0
:...
()...
print(l
[i],end
=","
)...(1
,3,5
),(1,3
,7),(1,5
,3),(1,5
,7),(1,7
,3),(1,7
,5),(
3,1,
5),(3,
1,7),(3,
5,1),(3,
5,7),(3,
7,1),(3,
7,5),
(5,1
,3),(5,1
,7),(5,3
,1),(5,3
,7),(5,7
,1),(5,7
,3),(
7,1,
3),(7,
1,5),(7,
3,1),(7,
3,5),(7,
5,1),(7,
5,3),
>>>
Java怎樣才能一行輸入多個整數為整個一維陣列賦值
何旭杭 public class Sum else if temp 0 System.out.println System.out.println 正數的和 posSum System.out.println 負數的和 negSum PS 標示符採用駝峰大小寫,增加可讀性。 int b new in...
有沒有 優雅的 python 倒著一行一行讀大檔案的例子
Justin Z file read backwards file read backwards 2.0.0 documentation 乙個現成的包,安裝 pip install file read backwards 官方Python 3的例子 from file read backwards ...
怎樣才能學好python呢?
月光木 先看基礎課,然後再選方向,去看一些定向的應用課 爬蟲,web開發,自動化辦公 就是說絕大部分的應用課,都是你會基礎的情況下才可以聽得懂,所以基礎一定要好,決定了你對乙個應用方向的理解深度,以後肯定能決定你能走多遠。 小蘋果 python學習其實並不難,看下面的幾篇回答就可以啦 0基礎,想自學...