# How to ignore external list in case of lists in list(without using Numpy)

## Issue

I writing a function that its input is- image_one, image_two, mask).
This function outputs a new image by calculating every new pixel according to the formula-

I wrote until now-

hight = len(image_one)
width = len(image_one[0])
new_image = [[0 for _ in range(width)] for _ in range(hight)]

for i in range(hight):
for j in range(width):
return new_image

The function dose work on double lists.
For example:

Input-

image_plus_mask([[50, 50, 50]], [[200, 200, 200]], [[0, 0.5, 1]])

Output(as expected)-

[[200, 125, 50]]

The problem is that it is not working on 3 lists, and I need it to work on both- 2 and 3 lists.(by 2 I mean-[[]], by 3 I mean- [[[]]])

For example-

Input-

[[[250,250,250], [0,0,0]],[[250,250,100],[1,11,13]]],[[0,0.5]]*2))

Expected Output-

[[[250, 250, 250,], [2,2,3]], [[250, 250, 100], [6, 11, 12]]]

What can I do?

## Solution

hight = len(image_one)
width = len(image_one[0])

#case: 3 lists
if isinstance(image_one[0][0], (list,tuple)):
depth = len(image_one[0][0])
new_image = [[[0 for _ in range(depth)] for _ in range(width)] for _ in range(hight)]
print(new_image)
for i in range(hight):
for j in range(width):
for k in range(depth):

#case: 2 lists
else:
new_image = [[0 for _ in range(width)] for _ in range(hight)]
for i in range(hight):
for j in range(width):

return new_image

you need to adjust your shape of new_image. Look at your expected Output for 3 lists and look inside the function what you define for new_image. Couldn’t work.

Output now: