编程学习之基础:数组排序
def sort_arrays(arrays):  
    # 将数组按照第一个元素进行排序
    arrays.sort(key=lambda x: x[0])
    
    # 检查是否需要继续按第二个元素排序
    need_sort = True
    while need_sort:
        need_sort = False
        for i in range(len(arrays) - 1):
            if arrays[i][0] == arrays[i+1][0]:
                if arrays[i][1] > arrays[i+1][1]:
                    arrays[i], arrays[i+1] = arrays[i+1], arrays[i]
                    need_sort = True
                    
        # 然后按照第三个元素排序         
        if need_sort:
            arrays.sort(key=lambda x: x[1])
Subscribe to LoveNft.eth
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.