才學不久,希望每天能記錄一篇
import random
def zidianxulie():#封裝整個函數
a=input(“請輸入字符串:”)
a1=sorted(a)#先對我輸入的字符串進行一個排序,簡單得到一個列表
l=[]#空列表的作用是爲了儲存我得到的目標字典序列
def leicheng(n):#爲下面程序中的循環次數得到基礎
if n==1:
return 1
else:
return n*leicheng(n-1)
chongfu= leicheng((len(a1)-len(set(a1)))+1)#考慮到有重複元素的做法
b=int(leicheng(len(a1))/chongfu)
while len(l)!=b:
st1=””
random.shuffle(a1)
for x in a1:
st1+=x
if st1 not in l:
l.append(st1)
else:
continue
print(sorted(l))
zidianxulie()