Skip to main content

A simple diff tool for dictionary and list

Project description

simple_diff

A simple diff tool for dictionary and list

>>> import simple_diff
>>> old_dict = {'a':1, 'b':2, 'c':3, 'd':4}
>>> new_dict = {'b':1, 'c':3, 'd':4, 'e':5}    
>>> 
>>> simple_diff.dict_diff(old_dict, new_dict)
{
  'created': [{'key': 'e', 'value': 5}], 
  'deleted': [{'key': 'a', 'value': 1}], 
  'unchanged': [{'key': 'd', 'value': 4}, {'key': 'c', 'value': 3}], 
  'modified': [{'old': {'key': 'b', 'value': 2}, 'new': {'key': 'b', 'value': 1}}]
}
>>> 
>>> old_list = [{'index':1, 'name': 'bob'}, {'index':2, 'name': 'john'}, {'index':3, 'name': 'tom'}]
>>> new_list = [{'index':2, 'name': 'john'}, {'index':3, 'name': 'kevin'}, {'index':4, 'name': 'mary'}]
>>> simple_diff.list_diff(old_list, new_list, key= 'index')             
{
  'created': [{'index': 4, 'name': 'mary'}], 
  'deleted': [{'index': 1, 'name': 'bob'}], 
  'unchanged': [{'index': 2, 'name': 'john'}], 
  'modified': [{'old': {'index': 3, 'name': 'tom'}, 'new': {'index': 3, 'name': 'kevin'}}]
}

Project details


Release history Release notifications

This version

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for simple-diff, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size simple_diff-0.1.0-py3-none-any.whl (2.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size simple-diff-0.1.0.tar.gz (1.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page