zoukankan      html  css  js  c++  java
  • Random words

    To choose a random word from the histogram, the simplest algorithm is to build a list with multiple copies of each word, according to the observed frequency, and then choose from the list:

                           

    The expression[word] * freq creates a list with freq copies of the string word (actually, to be more precise, the elements are references to the same string). The extend method is similar to append expect that the argument is a sequence.

    This algorithm works, but it is wildly inefficient; each time you choose a random word, it rebuilds the list, which is as big as the original book.

    If you generate a series of words from the book, you can get a sense of the vocabulary, but it probably won’t make much sense. The next section is about generating random text that makes more sense.

     

     

    from Thinking in Python

  • 相关阅读:
    WPF 中使用 Resource 实现多语言
    webapi入门 如何调用
    webapi入门2
    webapi 入门
    asp.net web page 中如何添加引用
    几个Is函数
    webGrid内容格式化
    Validation
    HTML FORM
    访问数据库
  • 原文地址:https://www.cnblogs.com/ryansunyu/p/3918067.html
Copyright © 2011-2022 走看看