• # -*- coding: utf-8 -*-
    """
    主要实现思路
    主要是根据手势密码锁来定义基本操作规则(只能连接临近的数字,不能越过数字进行连接),再运用类比法构造实现(不能出现重复的数字)。
    """
    #定义基本规则
    key=[[[1,2],[1,4],[1,5]],[[2,1],[2,3],[2,4],[2,5],[2,6]],[[3,2],[3,5],[3,6]],[[4,1],[4,2],[4,5],[4,7],[4,8]],[[5,1],[5,2],[5,3],[5,4],[5,6],[5,7],[5,8],[5,9]],[[6,3],[6,5],[6,8],[6,9],[6,2]],[[7,4],[7,5],[7,8]],[[8,7],[8,9],[8,4],[8,5,],[8,6]],[[9,6],[9,5],[9,8]]]
    
    #1个
    def rank1(key):
        skey=[]
        for i in range(1,10):
             skey.append(key[i-1][0][0])
        return skey
    #2个
    def rank2(key):
        skey=[]
        key1=rank1(key)
        for key2 in key1:
           for dkey in key[key2-1]:
                skey.append(dkey)
        return skey
    #3个
    def rank3(key):
        skey=[]
        key2=rank2(key)
        for dkey in key2:
            for key3 in key[dkey[-1]-1]:
                tim=[]
                if (key3[1] not in dkey) and (len(tim)<3):
                    for okey in dkey:
                            tim.append(okey)
                    tim.append(key3[1])
                    skey.append(tim)
        return skey
    #4个
    def rank4(key):
        skey=[]
        key2=rank3(key)
        for dkey in key2:
            for key3 in key[dkey[-1]-1]:
                tim=[]
                if (key3[1] not in dkey) and (len(tim)<4):
                    for okey in dkey:
                            tim.append(okey)
                    tim.append(key3[1])
                    skey.append(tim)
        return skey
    #5个
    def rank5(key):
        skey=[]
        key2=rank4(key)
        for dkey in key2:
            for key3 in key[dkey[-1]-1]:
                tim=[]
                if (key3[1] not in dkey) and (len(tim)<5):
                    for okey in dkey:
                            tim.append(okey)
                    tim.append(key3[1])
                    skey.append(tim)
        return skey
    
    #6个
    def rank6(key):
        skey=[]
        key2=rank5(key)
        for dkey in key2:
            for key3 in key[dkey[-1]-1]:
                tim=[]
                if (key3[1] not in dkey) and (len(tim)<5):
                    for okey in dkey:
                            tim.append(okey)
                    tim.append(key3[1])
                    skey.append(tim)
        return skey
    #7个
    def rank7(key):
        skey=[]
        key2=rank6(key)
        for dkey in key2:
            for key3 in key[dkey[-1]-1]:
                tim=[]
                if (key3[1] not in dkey) and (len(tim)<5):
                    for okey in dkey:
                            tim.append(okey)
                    tim.append(key3[1])
                    skey.append(tim)
        return skey
     #8个
    def rank8(key):
        skey=[]
        key2=rank7(key)
        for dkey in key2:
            for key3 in key[dkey[-1]-1]:
                tim=[]
                if (key3[1] not in dkey) and (len(tim)<5):
                    for okey in dkey:
                            tim.append(okey)
                    tim.append(key3[1])
                    skey.append(tim)
        return skey
    #9个
    def rank9(key):
        skey=[]
        key2=rank8(key)
        for dkey in key2:
            for key3 in key[dkey[-1]-1]:
                tim=[]
                if (key3[1] not in dkey) and (len(tim)<5):
                    for okey in dkey:
                            tim.append(okey)
                    tim.append(key3[1])
                    skey.append(tim)
        return skey
    
    
    print(rank4(key))