在python中查找单词的所有组合(上部和下部以及符号) [英] Find all combinations (upper and lower and symbols) of a word in python

查看:449
本文介绍了在python中查找单词的所有组合(上部和下部以及符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望它是星期一 - 它现在正在踢它,但我觉得应该非常容易 - 或者至少是优雅 - 给我一个大脑放屁。用例是这样的:

I hope it's Monday-itis kicking in at the moment, but something I feel should be quite easy - or at least elegant - is giving me a brain fart. The use case is this:

查找特定单词的所有可能组合,其中字母可以是任何大小写或用字母替换。例如:

Find all possible combinations of a specific word, where letters can be any case or replaced with letters. For instance:

Word:'密码'
组合:'PASSWORD','P @ ssw0rd','p @ 55w0rD'...

Word: 'Password' Combinations: 'PASSWORD', 'P@ssw0rd', 'p@55w0rD' ...

我不想写7个循环来找到它,即使它是一个一次性的脚本我们永远不会再使用。

I do not want to write 7 loops to find this out, even though it's a once off script we'll never ever use again.

推荐答案

import itertools

places = [
    "Pp",
    "Aa@",
    "Ss5",
    "Ss5",
    "Ww",
    "Oo0",
    "Rr",
    "Dd",
]

for letters in itertools.product(*places):
    print "".join(letters)

如果你需要处理任意单词,那么你需要编写代码来创建地方从字符串中列出。

If you need to handle arbitrary words, then you'll need to write code to create the places list from the string.

这篇关于在python中查找单词的所有组合(上部和下部以及符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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