Ben Chuanlong Du's Blog

It is never too late to learn.

Hands on the Python Library DeepDiff

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

In [1]:
pip3 install deepdiff
Collecting deepdiff
  Downloading deepdiff-5.2.3-py3-none-any.whl (64 kB)
     |████████████████████████████████| 64 kB 2.6 MB/s 
Collecting ordered-set==4.0.2
  Downloading ordered-set-4.0.2.tar.gz (10 kB)
Building wheels for collected packages: ordered-set
  Building wheel for ordered-set (setup.py) ... done
  Created wheel for ordered-set: filename=ordered_set-4.0.2-py2.py3-none-any.whl size=8209 sha256=92957b34a9d884c3fc2d0cb50fe17cbc3d0c82fc0b343b7fa74bb635c0f64213
  Stored in directory: /Users/dclong/Library/Caches/pip/wheels/a1/09/42/0b963b1d5423ddc87cb4ba9f475e09838d3813300b52a866ea
Successfully built ordered-set
Installing collected packages: ordered-set, deepdiff
Successfully installed deepdiff-5.2.3 ordered-set-4.0.2
In [2]:
from deepdiff import DeepDiff
In [3]:
t1 = {1: 1, 2: 2, 3: 3, 4: {"a": "hello", "b": [1, 2, 3]}}
t2 = {1: 1, 2: 2, 3: 3, 4: {"a": "hello", "b": [1, 3, 2, 3]}}
ddiff = DeepDiff(t1, t2, ignore_order=True)
ddiff
Out[3]:
{}
In [4]:
True if ddiff else False
Out[4]:
False
In [ ]:

Comments