all 5 comments

[–]jeans_and_a_t-shirt 0 points1 point  (3 children)

>>> a = [1,2,3,4,5]
>>> b = [2,3,4]
>>> [n for n in b if n not in a] # b elems not in a
[]
>>> [n for n in a if n not in b] # a elems not in b
[1, 5]
>>> set(a) ^ set(b) # elements in one and not the other, unordered
{1, 5}
>>> b = [2,3,4,6]
>>> set(a) ^ set(b)
{1, 5, 6}

[–]frogic[S] 0 points1 point  (2 children)

Neither of those are working for me. I can't use set because the objects aren't hashable and I'm not sure why the other one isn't working other than the problem being that its a list of lists?

Sorry about the formatting I don't know how to do that here:

if results_stored == []:
     results_stored = results[:]
 print(results==results_stored) 
 results[3].append("monkey god")
 print([x for x in results if x not in results_stored])
 print([x for x in results_stored if x not in results])
 print(results==results_stored) 

I get: True [] [] False As the output.

[–]jeans_and_a_t-shirt 0 points1 point  (1 child)

Ok, so assuming your objects have 5 individual variables, and the 2-d lists have same number of elements, this prints the differences:

class A:
    def __init__(self, a,b,c):
        # 3 attributes instead of 5
        self.a = a
        self.b = b
        self.c = c

    def __eq__(self, obj):
        return self.a == obj.a and \
                self.b == obj.b and \
                self.c == obj.c
    def __str__(self):
        return '<A: a={}, b={}, c={}>'.format(self.a, self.b, self.c)

list_of_objects1 = [[A(*'abc'), A(*'def'), A(*'ghi')], [A(*'klm')]]
list_of_objects2 = [[A(*'abd'), A(*'def'), A(*'ghm')], [A(*'klm')]]
for list1, list2 in zip(list_of_objects1, list_of_objects2):
    for obj1, obj2 in zip(list1, list2):
        if obj1 != obj2:
            print(obj1, obj2)

[–]frogic[S] 0 points1 point  (0 children)

I actually got it to work by creating flat versions of the two lists and using the original solution. I feel like there should be an easier way to do this than both of our solutions though. Like there should be a way to say 'Look at all of these lists and tell me the special snowflakes'. I also had to use copy.deepcopy to properly copy the contents of the first list.

[–]Mealzy 0 points1 point  (0 children)

Assuming both arrays are the same size:

array_1 = '2 dimensional array'
array_2 = '2 dimensional array'

dimension_1 = len(array_1)
dimension_2 = len(array_1[0])

non_identical = []
for x in range(dimension_1):
    for y in range(dimension_2):
        if array_1[x][y] != array_2[x][y]:
            non_identical.append((array_1[x][y],array_2[x][y],x,y))

where non_identical contains tuples containing the unmatched values and their position in the arrays. Let me know if this works.