0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonで辞書の内容が同じかハッシュ値で調べる方法

Posted at

Pythonで辞書の内容が同じかハッシュ値で調べる方法

辞書型はキーの並び順が決まってないので、単純に文字列化してmd5求めてもだめ。

ズバリこれ

import hashlib
import json

data = ['only', 'lists', [1,2,3], 'dictionaries', {'a':0,'b':1}, 'numbers', 47, 'strings']
data_md5 = hashlib.md5(json.dumps(data, sort_keys=True)).hexdigest()

参考
https://stackoverflow.com/questions/5417949/computing-an-md5-hash-of-a-data-structure

0
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?