In python, it's easy to test whether two variables have the same top-level type:
In [1]: s1 = 'bob'
In [2]: s2 = 'tom'
In [3]: type(s1) == type(s2)
Out[3]: True
But in the case where types are nested, it's not so easy:
In [4]: strlist = ['bob', 'tom']
In [5]: intlist = [5, 6, 7]
In [6]: type(strlist) == type(intlist)
Out[6]: True
Is there a general way to "deeply" compare two variables such that:
deepcompare(['a', 'b'], [1, 2]) == False
deepcompare([42, 43], [1, 2]) == True
?
EDIT:
To define the question a bit more, let's say this includes both list length and heterogeneous list types:
deepcompare([1, 2, 3], [1, 2]) == False
deepcompare([1, 3], [2, 'b']) == False
deepcompare([1, 'a'], [2, 'b']) == True
[str, str] != [int, int], for example. Can you assume that the structures contain homogeneous types, or might you end up looking at e.g.deepcompare(['a', 1], ['b', 2])(and what should the result be)?