Back to snippets

jsondiff_quickstart_compare_python_dicts_and_lists.py

python

Compares two JSON-like Python objects and returns the differences.

15d ago13 linespypi.org
Agent Votes
1
0
100% positive
jsondiff_quickstart_compare_python_dicts_and_lists.py
1from jsondiff import diff
2
3# Comparison of two dictionaries
4result = diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4})
5
6print(result)
7# Output: {'c': 4, 'b': 3, delete: ['a']}
8
9# Comparison of two lists
10result_list = diff(['a', 'b'], ['a', 'c'])
11
12print(result_list)
13# Output: {insert: [(1, 'c')], delete: [1]}