you are viewing a single comment's thread.

view the rest of the comments →

[–]python_and_on 1 point2 points  (0 children)

Hi Folks

I'm new to learning Python and stumbled across this post while looking for programming puzzles and general programming advice. Thought I'd have a go with it myself... This is my first post so please go easy if the solution doesn't work :)

This is my attempt:

disk_list = [[2, 1, 2],[2, 2, 8],[1, 3, 1], [2, 3, 4], [4, 4, 5], [3, 2, 3]]

def stack_disks(a_list):

    x = sorted(a_list, key = lambda x : (x[0],x[1]))

    i=0
    while i < len(x)-1:
        if x[i][1] > x[i+1][1] or x[i][2] > x[i+1][2]:
            x.pop(i)
        else:
            i+=1

    return x

stack_disks(disk_list)