加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 如何生成几个字母的所有可能排列的列表?

发布时间:2020-12-20 12:24:00 所属栏目:Python 来源:网络整理
导读:参见英文答案 How to generate all permutations of a list in Python????????????????????????????????????30个 ???????????? Randomize a string input into all possibilities????????????????????????????????????1个 所以我正在创建一个单词生成器,它接
参见英文答案 > How to generate all permutations of a list in Python????????????????????????????????????30个
>???????????? Randomize a string input into all possibilities????????????????????????????????????1个
所以我正在创建一个单词生成器,它接受几个输入的字母,将它们放在所有可能的位置,并将它们与文档匹配以查找单词.如果我接近这个错误请告诉我!如果不是我怎么能这样做?
谢谢

解决方法

要生成给定字母列表的所有排列,请使用itertools模块.

import itertools 
for word in itertools.permutations( list_of_letters ):
   print ''.join(word)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读