在看 Think Python,有一道练习题没看明白,能帮忙翻译一下吗? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zeroday

在看 Think Python,有一道练习题没看明白,能帮忙翻译一下吗?

  •  
  •   zeroday 2015 年 2 月 8 日 2739 次点击
    这是一个创建于 4093 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Exercise 12.2. In this example, ties are broken by comparing words, so words with the same length appear in reverse alphabetical order.

    For other applications you might want to break ties at random.

    Modify this example so that words with the same length appear in random order.

    Hint: see the random function in the random module.

    4 条回复    2015-02-08 13:19:24 +08:00
    manoon
        1
    manoon  
       2015 年 2 月 8 日via Android   1
    words with the same length appear in random order.

    Hint: see the random function in the random module.


    上一节是练习使用升序/降序

    这一节,你就先找出len相同的words,然后随机排序就行啦。

    (愚见,仅供参考)
    zeroday
        2
    zeroday  
    OP
       2015 年 2 月 8 日
    @manoon 谢谢,不理解 ties are broken by comparing words 和For other applications you might want to break ties at random. 主要是不理解 ties break 的意思。
    zeroday
        3
    zeroday  
    OP
       2015 年 2 月 8 日
    @manoon 奇怪的是,上一节练习的例子是根据列表中单词的长度,进行降序排列,代码是这样的。

    https://gist.github.com/arcticlion/f75f89fd1c0ff4ef1cde

    运行结果是这样的:

    wooooo
    applee
    Harlod
    Finich
    world
    tuple
    hello
    apple
    nba
    ibm

    对于相同的长度的单词,打印出现的顺序本来就是随机。
    zeroday
        4
    zeroday  
    OP
       2015 年 2 月 8 日
    突然明白了,上一例在相同长度上的输出虽然不是按字母表顺序,但是每次输出都是固定的。练习需要我修改上一例的代码,让每次在相同长度上的输出是不固定的。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     867 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 21:09 PVG 05:09 LAX 14:09 JFK 17:09
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86