字典排序,初始化,簡單使用

2021-09-01 11:13:02 字數 862 閱讀 6578

想對字典wordhash排序:

通過list實現:wordlist

wordhash=

wordlist = [('\ufeff', 1), ('calvin', 1), ('shi', 1), ('鏈結', 1), ('www', 1), ('zhihu', 1), ('question', 1), ('27068465', 1)]

item:item[1]代表是元組('calvin', 1)中的第二個元素『1』進行排序
reverse=false代表詞頻從小到大
wordhash = {}   #字典的初始化

wordhash = cipin(content)

wordlist = sorted(wordhash.items(),key=lambda item:item[1],reverse=false)

for tuple in wordlist:

word = tuple[0]

print(word+' '+str(wordhash[word]))

判斷某個key是否在字典中

def cipin(content):

wordhash = {}

words = content.split()

for word in words:

if word in wordhash:

wordhash[word] += 1

else:

wordhash[word] = 1

return wordhash

git初始化簡單設定

git config global user.name gaochaowie git config global user.email gaochaoweino qq.com git init git add readme.txt git commit m wrote a readme file g...

GIT入門之一 初始化,簡單使用,分支

ubuntu下 sudo apt get install git sudo apt get install gitk windows下 msysgit 1,把冰箱門開啟 2,把大象放進去 3,把冰箱門關上 1,cd 該目錄 2,敲 git init 3,回車 git status git add f...

linux memblock 初始化簡介

setup machine fdt fdt pointer early init dt scan early init dt scan nodes 從dts中獲取 記憶體容量,位址資訊 setup memory,calling early init dt add memory arch of sca...