How to simplify multiple nested loops in python?

  Kiến thức lập trình

Is there a way for me to avoid writing out all of these loops by hand?

Something like:

for x in range(6):
    run_this_code.("for i(x) in range(6):")
    do stuff

FYI, Polygon is a list of 6 lists.

My code:

for i0 in range(6):
    for i1 in range(6):
        for i2 in range(6):
            for i3 in range(6):
                for i4 in range(6):
                    for i5 in range(6):
                        for p0 in Polygon[i0]:
                            for p1 in Polygon[i1]:
                                if p0[1] == p1[0]:
                                    for p2 in Polygon[i2]:
                                        if p1[1] == p2[0]:
                                            for p3 in Polygon[i3]:
                                                if p2[1] == p3[0]:
                                                    for p4 in Polygon[i4]:
                                                        if p3[1] == p4[0]:
                                                            for p5 in Polygon[i5]:
                                                                if p4[1] == p5[0] and p5[1] == p0[0]:
                                                                    p = [i0,i1,i2,i3,i4,i5]
                                                                    if all(x in p for x in range(6)):


Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website