このコードは Web URL (nytimes.com) を受け取り、上位 10 の単語の出現とそれらの出現回数のリストを出力します。トップ 10 の単語を取得していますが、カウントが nil になっています。出現回数を表示するようにカウント変数を修正するのを手伝ってもらえますか? ありがとう!
local http = require("socket.http")
local url = "http://www.nytimes.com"
local body = http.request(url)
local words = {}
for word in string.gmatch(body,"%a+") do
-- print(word)
words[word] = (words[word] or 0) + 1
end
for word, count in pairs(words) do
-- print(words,count)
end
function top1(t)
local max = 0
local maxword
for word, count in pairs(t) do
if count > max then
max = count
maxword = word
end
end
t[maxword] = nil
return maxword, count
end
for i = 1, 10 do
print(top1(words))
end