Re: [問題] 1-9位數不重複印出來(Python)

看板Programming作者 (豬豬毅)時間7年前 (2017/05/13 15:41), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
偷拿itertools來改,9位數跑完大約7~8秒,供參考 def creator(num): ans = list() pools = [x for x in range(1,10)] for n in range(num): result = [[]] for i in range(n+1): result = [x+[y] for x in result for y in pools if y not in x] for res in result: ans.append(sum([k * (10**j) for j, k in enumerate(res)])) ans.sort() print(*ans) if __name__ == '__main__': creator(int(input())) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 39.9.168.141 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1494661305.A.036.html
文章代碼(AID): #1P5hYv0s (Programming)
文章代碼(AID): #1P5hYv0s (Programming)