python中的单词表生成器[重复]

Posted

技术标签:

【中文标题】python中的单词表生成器[重复]【英文标题】:Wordlist generator in python [duplicate] 【发布时间】:2016-04-20 12:37:27 【问题描述】:

经过大量的搜索和失败以及愚蠢的压力,我想问,如何在 python 中构建一个单词表生成器?

我的情况 要使用的字母和数字 (abcdef0123456789) 长度(72 个字符)

生成类似的东西:

“18516a9744529fcf5f01cc12b86fe5db614db6d688d826f20d501b343199f2de921a6310”

【问题讨论】:

它能产生各种组合吗? (我知道听起来很疯狂) 你也可以试试这个:from random import randrange; ''.join(hex(randrange(16))[2:] for _ in range(72)). 【参考方案1】:

是的-每种组合-按照我上面发布的链接示例: Random string generation with upper case letters and digits in Python

你可以这样做:

import random

# same function as in the link, but size set to your desired length (72)
# instead of using the strings module, i'm just making a list of 
# allowable characters. there's cleaner ways to do this, but i wanted to 
# make it clear for you

def id_generator(size=72, chars= (['a','b','c','d', 'e', 'f','0','1','2','3','4','5','6','7','8','9'])):
    return ''.join(random.choice(chars) for _ in range(size))
x = id_generator()
print x

嗯。 . .如果您试图生成每个可能组合的完整列表,那不太可能顺利,因为大约有 5 x 10E86 种可能的组合。这是很多。

【讨论】:

我这样做了:import itertools >>> >>> chrs = 'abcef0123456789' >>> n = 72 >>> >>> for xs in itertools.product(chrs, repeat=n) : ... print ''.join(xs)' 学分:link Btw,它有很多尝试,并且需要一些时间 在所有尝试之后,有一种方法可以在 .txt 中自动保存完整列表吗?

以上是关于python中的单词表生成器[重复]的主要内容,如果未能解决你的问题,请参考以下文章

在 python 中构建一个单词搜索生成器

从 JSON 生成 javascript 中的 HTML 表 [重复]

同一生成器函数的不同调用中的最后一个小数位精度变化[python] [重复]

python 生成器函数可帮助解析段落,行和单词

Python中的迭代器生成器

动态生成表中的另一行后,JQuery函数不起作用[重复]