當前位置:首頁 » 編程語言 » python全排列組合

python全排列組合

發布時間: 2024-01-08 05:57:04

⑴ 如何用Python列出N個數字的所有排列組合

>> from itertools import combinations, permutations
>> permutations([1, 2, 3], 2)
<itertools.permutations at 0x7febfd880fc0>
# 可迭代對象
>> list(permutations([1, 2, 3], 2)) #排列
[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
>> list(combinations([1, 2, 3], 2)) #組合
[(1, 2), (1, 3), (2, 3)]

熱點內容
為什麼登錄小馬鎮顯示密碼錯誤 發布:2025-08-27 06:20:38 瀏覽:893
php訂單號 發布:2025-08-27 06:20:37 瀏覽:615
我的世界伺服器娘清理 發布:2025-08-27 06:19:08 瀏覽:797
kmp手機ftp 發布:2025-08-27 06:09:57 瀏覽:760
如何編寫sql的lua腳本 發布:2025-08-27 05:50:30 瀏覽:918
ultraedit反編譯 發布:2025-08-27 05:48:15 瀏覽:839
電源編程 發布:2025-08-27 05:42:18 瀏覽:626
mysql存儲過程elseif 發布:2025-08-27 05:20:02 瀏覽:149
python的內存機制 發布:2025-08-27 05:19:29 瀏覽:427
如何反編譯通達信 發布:2025-08-27 05:02:01 瀏覽:705