python - 如何将一个 word 里的几百个单词随机分组
PHP中文网
PHP中文网 2017-04-18 09:50:36
0
1
470

现有一个 word 文件,里面有 200 个单词(一个单词一行),如果想随机分 18 组,每组 50 个,再输出到 word 里,可以用 python 实现吗?

具体该用什么实现?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
Ty80

You can use the product function in the itertools module. The approximate code is as follows:


import itertools
lst = ['a', 'b', 'c'] #从word文件中将单词读到lst列表
repeat = 2 #这里就是你想分组的数目
for x in itertools.product(lst, repeat=2):
    print x
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!