Home  >  Q&A  >  body text

python - 如何将一个 word 里的几百个单词随机分组

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

具体该用什么实现?

PHP中文网PHP中文网2741 days ago477

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:52:36

    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
    

    reply
    0
  • Cancelreply