作爲python 練手的一個小例子
數據來源:
鏈接:https://pan.baidu.com/s/1u2c7O-617MboXSwBHnoOcA 提取碼:vX47
def words_static(file_path):
words_static = dict()
with open(file_path,"r") as file :
for line in file:
if line:
words = line.split(" ")
for word in words:
words_static.setdefault(word,0)
words_static[word] += 1
words_static_sorted = sorted(words_static.items(), key=lambda words_static:words_static[1],reverse = True)
new_words_static_sorted = []
for i in words_static_sorted:
new_words_static_sorted.append((i[1],i[0]))
return new_words_static_sorted
本例子來自於 浙江大學吳明輝教授在MOOC開設的 深度學習開發-Tensorflow 個人覺得講解的非常好 剛興趣的可以看一下 非常適合零基礎的小白學習TensorFlow