python单词表首字母排序_Python单词表排列

该脚本使用Python的itertools库生成列表中单词的各种组合,包括最多3个单词的组合。它读取一个名为'List.txt'的文件,然后通过permutations函数创建所有可能的组合,并将结果写入'powerset.txt'文件。
摘要由CSDN通过智能技术生成

如何让这个脚本从一个列表中最多替换3个单词的组合?在

在列表.txt由4个字符串组成:pass

10

test

word

而不是从一个词到四个词

^{pr2}$

我希望最后的组合是:output > testpassword, passtestword, 10wordtest,....etc

我的代码:from itertools import permutations

import os

# GET FILE

script_dir = os.path.dirname(os.path.realpath(__file__))

wordlist_rel_path = "List.txt"

wordlist_abs_file_path = os.path.join(script_dir, wordlist_rel_path)

# READ WORD LIST FROM FILE

word_list = []

print ("\ninput file is:", wordlist_abs_file_path,"\n")

with open(wordlist_abs_file_path) as wordlist:

for line in wordlist:

word_list.append(line.rstrip())

# PRINT INPUT LIST

print ("input list contains:")

print(word_list,"\n")

# GENERATE POWERSET

powers

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值