gpt4 book ai didi

python - 如何从 Python 中的预定义模板列出可能的组合

转载 作者:太空宇宙 更新时间:2023-11-03 14:57:05 25 4
gpt4 key购买 nike

我正在制作一些需要输入模板的东西。

我需要生成模板的大量可能性

[ "Catman001","Catman002","Catman003","Catman004",....,"Catman999" ]
[ "01Catman01","01Catman02","01Catman03","01Catman04",...,"02Catman01","02Catman02"]
[ "ProAGamer","ProbGamer","ProCGamer","ProDGamer",.....,"ProZGamer"]
[ "XxGamerAxX_01","XxGamerAxX_02","XxGamerAxX_03",.....,"XxGamerBxX_01","XxGamerBxX_02",.....,"XxGamerZxX_99"]

我有很多模板,因此我希望得到一个可用于上述所有模板的答案

我尝试过以下操作:

Template = Catman{}
CompleteList = []

for i in range(1000):
CompleteList.append("Template".format(Template,i))

print CompleteList

仅适用于数字。

还有

Template = "Pro{}Gamer"

CompletedList = []

AToZ = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
atoz = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for Alphab in AToZ:
CompletedList.append(Template.format(Alphab))
for Alphab in atoz:
CompletedList.append(Template.format(Alphab))

print CompletedList

仅适用于一个字母。

如果您查看了我所做的几个示例,它会列出所有可能的组合,我希望代码如下所示:

AToZ = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
atoz = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
Nums = ["0","1","2","3","4","5","6","7","8","9"]

Template = raw_input("Type In The Template")
Template = "XxGamer#xX_%%"

CompletedList = []

'''
# = Capital Letter
$ = Non Capital Letter
% = Numbers
'''

def TemplateCombination(Template,CompletedList):
if ("#" in Template):
# Adds All Possible Combinations Of Capital Letters
if ("$" in Template):
# Add All Possible Combinations Of Non Capital letters
if ("%" in template):
# Add All Possible Combinations Of Numbers
return CompletedList

TemplateCombination(Template,CompletedList)

print CompletedList

对于那些仍然感到困惑的人,我正在尝试制作一个列表,其中包含预制模板中可能的组合,例如

Input : "Test%Section"

应该输出

OutPut : [ "Test1Section","Test2Section","Test3Section","Test4Section","Test5Section","Test6Section","Test7Section","Test8Section","Test9Section"]

我的问题是我不知道该怎么做。

最佳答案

您可以为#$编写相应的函数。
或者您可以增强扩展功能。

def expand_nums(to_expand):
res = list()
for n in range(0,10):
g = re.sub(r'%', str(n), to_expand, 1)
res.append(g)

return res

res = ['asd%kk%lk%lk%zz']
while res[0].find('%') != -1:
rres = list()
for r in res:
rres += expand_nums(r)
res = rres

print(rres)

关于python - 如何从 Python 中的预定义模板列出可能的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45457751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com