

def check(x):
    if x < 0: return 0
    if x > 255: return 255
    return x


def upzip(lst):
    res = [] 
    for i in lst:
        res.append(check(255 - i))
    return res


def invert(lst):
    arr = [] 
    for l in lst:
        new_row = []
        for ll in l:
            new_row.append(upzip(ll))
        arr.append(new_row)
    return arr


class Test:
    def assert_equals(a,b):
        try:
            assert a == b
        except AssertionError:
            print(f"{a}\n > should equal \n\t{b}")
TestsConsoleTest = Test            

TestsConsoleTest.assert_equals(invert([
	[[255,255,255], [255,255,255]],
	[[255,255,255], [255,255,255]]
]), [
	[[0,0,0], [0,0,0]],
	[[0,0,0], [0,0,0]]
])

Test.assert_equals(invert([
	[[0,0,0], [0,0,0], [0,0,0]],
	[[0,0,0], [0,0,0], [0,0,0]],
	[[0,0,0], [0,0,0], [0,0,0]]
]), [
	[[255,255,255], [255,255,255], [255,255,255]],
	[[255,255,255], [255,255,255], [255,255,255]],
	[[255,255,255], [255,255,255], [255,255,255]]
])

Test.assert_equals(invert([
	[[0,0,255], [0,0,0], [0,0,157], [100,229,4]],
	[[100,0,3], [1,100,0], [0,10,0], [0,168,0]],
	[[16,30,0], [0,125,0], [15,0,9], [0,139,0]],
	[[200,2,0], [0,125,0], [0,0,9], [0,200,0]]
]), [
	[[255,255,0], [255,255,255], [255,255,98], [155,26,251]],
	[[155,255,252], [254,155,255], [255,245,255], [255,87,255]],
	[[239,225,255], [255,130,255], [240,255,246], [255,116,255]],
	[[55,253,255], [255,130,255], [255,255,246], [255,55,255]]
])

Test.assert_equals(invert([
	[[0,255,255], [256,255,255]],
	[[255,-1,255], [255,255,255]]
]), [
	[[255,0,0], [0,0,0]],
	[[0,255,0], [0,0,0]]
])