如何生成几个字母的所有可能排列的列表? [英] How can I generate a list of all possible permutations of several letters?

查看:169
本文介绍了如何生成几个字母的所有可能排列的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在制作一个单词生成器,该单词生成器接受几个输入的字母,将它们放置在所有可能的位置,然后将它们与文档匹配以查找单词.如果我要解决这个错误,请告诉我!如果没有,我该怎么办? 谢谢

So I am making a word generator that takes several inputted letters, puts them in all possible positions, and matches them with a document to find words. If I am approaching this wrong please tell me! If not how can I do this? Thanks

推荐答案

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

to generate all permutations of a given list of letters, use the itertools module.

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

这篇关于如何生成几个字母的所有可能排列的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆