數據結構學習筆記15(北大公開課)目錄
散列
一、知識概覽
本章主要講解散列、散列函數、區塊鏈,知識概覽如下。
1.1 散列
1.2 散列函數
1.3 散列函數應用
重點介紹區塊鏈
二、python散列函數庫
import hashlib
u1=hashlib.md5("hello world!".encode("utf-8")).hexdigest()
u2=hashlib.sha1("hello world!".encode("utf-8")).hexdigest()
print(u1)
print(u2)
輸出
fc3ff98e8c6a0d3087d515c0473f8677
430ce34d020724ed75a196dfc2ad67c77772d169
如果報錯
Unicode-objects must be encoded before hashing
hash前必須把數據轉換成bytes類型,注意.encode(“utf-8”)