[英]Generating all possible combinations of the content of multiple lists with custom characters inbetween
I couldnt find any solution for my problem here so ill just post it maybe someone can help me ^^我在这里找不到任何解决我的问题的方法,所以生病了,也许有人可以帮助我 ^^
This is how the program looks like right now:这是程序现在的样子:
def dorkgen():
title()
kw = ['mcdonalds', 'kfc', 'doordash', 'taco bell']
param = ['oid', 'ap', 'utm_source', 'PageName', 'div', 'ID']
pageform = ['php', 'asp', 'aspx', 'htm', 'html']
keyword = random.choice(kw)
parameter = random.choice(param)
pageformat = random.choice(pageform)
print("\n " + keyword + " " + "." + pageformat + "?" + parameter + "=")
anykey = input("\n Enter any key to return to the main menu...")
mainMenu()
And I want to generate all the possible generations of kw, param, and pageform lists with custom characters inbetween if anybody can help I would really appreciate.如果有人可以提供帮助,我想生成所有可能的 kw、param 和 pageform 列表,其中包含自定义字符,我将不胜感激。
you can just:你可以:
[f"\n {k} =.{pf}?{prm}=" for k in kw for pf in pageform for prm in param]
It will generate a list with all of the possible combinations of those three lists.它将生成一个列表,其中包含这三个列表的所有可能组合。
Final code:最终代码:
def dorkgen():
title()
kw = ['mcdonalds', 'kfc', 'doordash', 'taco bell']
param = ['oid', 'ap', 'utm_source', 'PageName', 'div', 'ID']
pageform = ['php', 'asp', 'aspx', 'htm', 'html']
for ln in [f"\n {k} =.{pf}?{prm}=" for k in kw for pf in pageform for prm in param]:
print(ln)
anykey = input("\n Enter any key to return to the main menu...")
mainMenu()
You can use three for loops in a row to print all possibilities.您可以连续使用三个 for 循环来打印所有可能性。
import random
kw = ['mcdonalds', 'kfc', 'doordash', 'taco bell']
param = ['oid', 'ap', 'utm_source', 'PageName', 'div', 'ID']
pageform = ['php', 'asp', 'aspx', 'htm', 'html']
for i in kw:
for x in param:
for y in pageform:
print (i,x,y)
''' '''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.