Python排列代码挂起/冻结整个pc
我的简单排列代码只适用于不到4-5个排列,但会冻结整个系统,每当我提高值时,所有输入都会无响应……我还尝试在Android手机(Sd 636)上运行它,它会使终端崩溃。下面是代码:Python排列代码挂起/冻结整个pc,python,python-3.x,permutation,freeze,Python,Python 3.x,Permutation,Freeze,我的简单排列代码只适用于不到4-5个排列,但会冻结整个系统,每当我提高值时,所有输入都会无响应……我还尝试在Android手机(Sd 636)上运行它,它会使终端崩溃。下面是代码: import itertools with open('input.txt') as file: # regardless words are separated by space or newline, parse it all_words = [word for line in fil
import itertools
with open('input.txt') as file:
# regardless words are separated by space or newline, parse it
all_words = [word for line in file for word in line.split()]
all_permutations = [' '.join(item) for i in range(1, len(all_words) + 1) for item in itertools.permutations(all_words, i)]
with open('wordlist.txt', 'w+') as op:
# print(all_permutations)
for item in all_permutations:
op.write(f'{item}\n')
我的pc Intel Pentium 4(无GPU)Kali Linux 2020?1制作
所有排列
可能会有很大的帮助:所有排列=(''.join(item)for i范围内(1,len(all_words)+1)for itertools中的item.permutations(all_words,i))
(注意外面的大括号)谢谢,但是先生,我只是一个初学者,我可以复制、剪切、粘贴它吗(这是我的第二天)是的,你应该可以粘贴它而不需要做其他更改。从[]
到()
的更改将其从列表理解更改为生成器表达式。后者只在需要时生成元素,而不是预先生成所有元素。