給出數組(list),生成各種可能的組合,不排序

Python自帶的itertools模塊就能實現

import itertools
nums = itertools.permutations([1,2,3])
for x in nums:
    print(x)

>>>
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)
發佈了124 篇原創文章 · 獲贊 27 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章