Python对数列进行全排列
生活随笔
收集整理的這篇文章主要介紹了
Python对数列进行全排列
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
輸入:
1?數列的個數
2?數列
輸出:對數列進行全排列
import itertoolsnum = int(input()) arr = input("") li = [int(num) for num in arr.split()] if len(li) == num:pailie = list(itertools.permutations(li))for x in pailie:for y in x:print(y, end=' ')print()運行結果:
輸入:3
? ? ? ? ? 1 2 3
輸出:1 2 3?
? ? ? ? ? ?1 3 2?
? ? ? ? ? ?2 1 3?
? ? ? ? ? ?2 3 1?
? ? ? ? ? ?3 1 2?
? ? ? ? ? ?3 2 1?
總結
以上是生活随笔為你收集整理的Python对数列进行全排列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python输入多行多组数据两个两求和
- 下一篇: Python实现多行数据读入