数据结构学习笔记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”)