Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare two complex data structures?

I have some nested datastructures, each something like:

[ ('foo', [ {'a':1, 'b':2},
                 {'a':3.3, 'b':7} ]),
  ('bar', [ {'a':4, 'd':'efg', 'e':False} ])   ]

I need to compare these structures, to see if there are any differences. Short of writing a function to explicitly walk the structure, is there an existing library or method of doing this kind of recursive comparison?

like image 784
Phil H Avatar asked May 04 '10 10:05

Phil H


1 Answers

The built-in aggregation types (list, tuple, dict, etc.) already support equality and relational comparison. For types you create, you need to implement the rich comparison methods.

like image 141
Ignacio Vazquez-Abrams Avatar answered Sep 18 '22 12:09

Ignacio Vazquez-Abrams