V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
juventusryp
V2EX  ›  Python

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

  •  
  •   juventusryp · 2016-11-02 17:42:57 +08:00 · 2224 次点击
    这是一个创建于 2733 天前的主题,其中的信息可能已经有所发展或是发生改变。
    现有一个 word 文件,里面有 200 个单词(一个单词一行),如果想随机分 18 组,每组 50 个,再输出到 word 里,可以用 python 实现吗?

    具体该用什么实现?
    3 条回复    2016-11-02 18:05:32 +08:00
    purebluesong
        1
    purebluesong  
       2016-11-02 17:49:32 +08:00
    shuffle
    linuxplus
        2
    linuxplus  
       2016-11-02 17:55:27 +08:00
    直接命令行操作如何?
    $ split -l 50 abc.txt

    或者先简单乱序,再 split ?
    while read i; do echo "$i $RANDOM"; done< abc.txt | sort -k2n | cut -d" " -f1
    jimzhong
        3
    jimzhong  
       2016-11-02 18:05:32 +08:00
    random.shuffle(words)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2750 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:16 · PVG 18:16 · LAX 03:16 · JFK 06:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.