# 在Python中的嵌套列表上进行迭代/双重迭代

``````A1, A6 = [157, 157, 0], [407, 157, 0]
A2, A7 = [207, 157, 0], [457, 157, 0]
``````

``````A_LIST = [A1, A2, A3, A4, A5, A6, A7, A8, A9, AX]
``````

``````def between(x, val):
if val <= x <= val + 50:
return True

def check_pressed():
mouse_x, mouse_y = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if click != (0, 0, 0):
i = 0
for i in A_LIST:
if between(mouse_x, A_LIST[i]) is True and between(mouse_y, A_LIST[i]) is True:
``````

This approach brings an error saying `unexpected type` reffering to "i". I also tried this format: `A_LIST[i]`, but then it said `IndexError: list index out of range`. Let's say this problem is solved, then how could i "feed" this iteration with nested lists other than `A_LIST`? Like, taking 10 such sets (`B_LIST`, `C_LIST`, etc...), putting them into yet another list over which I would iterate.

``````def between(x, val):
if val <= x <= val + 50:
return True
else :
return False  # don't forget this one

if click != (0, 0, 0):
# i = 0  <-- don't need this line
for i in A_LIST:
if between(mouse_x, i) and between(mouse_y, i) :
# something you like
``````