首页 > 解决方案 > 如何制作大量Z1189不同排列的网站?

问题描述

所以我试图找到一个置换字母的不同网站。这是为了寻宝。例如,我需要创建一个这样的链接:http: //geocaching.com/geocache/GCZ1189 所以我想在我的浏览器中打开 120 种不同的排列。唯一的区别是“Z1189”链接的其余部分将保持不变:)

所以我在网上找到了这段代码。并尝试了最后一部分作为测试。但没有成功。

# Python function to print permutations of a given list 
def permutation(lst): 

    # If lst is empty then there are no permutations 
    if len(lst) == 0: 
        return [] 

    # If there is only one element in lst then, only 
    # one permuatation is possible 
    if len(lst) == 1: 
        return [lst] 

    # Find the permutations for lst if there are 
    # more than 1 characters 

    l = [] # empty list that will store current permutation 

    # Iterate the input(lst) and calculate the permutation 
    for i in range(len(lst)): 
       m = lst[i] 

       # Extract lst[i] or m from the list.  remLst is 
       # remaining list 
       remLst = lst[:i] + lst[i+1:] 

       # Generating all permutations where m is first 
       # element 
       for p in permutation(remLst): 
           l.append([m] + p) 
    return l 

data = list('Z1189') 
for p in permutation(data): 
    print (p)


#I've made this below. Not working as I wanting it to though
for p in permutation(data):
    o = list(p)
    o = ''.join(o)
    permutation(data).append(o)
    print(o)

所以我希望它打开所有可以通过这种排列完成的不同网页。所以与 Z1189 的链接。但是http://geocaching.com/geocache/GC。会像每一页一样。就像这里一样。当我使用控制台输入“打印排列(数据)”时,它只显示一个长文本。用我刚刚删除的东西。像 [, ] 之类的。谁能帮我?

标签: pythonpython-3.x

解决方案


推荐阅读