【发布时间】:2018-04-09 21:43:56
【问题描述】:
我正在尝试将列表放入字典并计算列表中每个单词的出现次数。我不明白的唯一问题是,当我使用更新函数时,它将 x 作为字典键,当我希望 x 成为 list_ 的 x 值时。我是 python 新手,所以任何建议都值得赞赏。谢谢
list_ = ["hello", "there", "friend", "hello"]
d = {}
for x in list_:
d.update(x = list_.count(x))
【问题讨论】:
标签: python list dictionary for-loop key