藏頭詩

  1. 利用之前蒐集的詩文,建立一個二維字典 wordDict。
  2. 然後利用 Markov Text Generator,試著產生一首「藏頭詩」。
  3. 主程式大概如下:
    print("===== 藏頭詩 =====")
    initials = '天下為公'
    for initialWord in initials:
        text = ""
        currentWord = initialWord
        i = 0
        while True:
            i += 1
            text += currentWord
            if currentWord not in wordDict:
                currentWord = initialWord
            currentWord = retrieveRandomWord(wordDict[currentWord])
            if currentWord == '\n': break
        print(text)