美文网首页
无聊~更改数组数据状态, 记录,待优化

无聊~更改数组数据状态, 记录,待优化

作者: 阿猫阿狗py | 来源:发表于2021-07-14 18:07 被阅读0次
    # encoding: utf-8
    
    """
    [[1,2,3,4,5,6],
    [1,2,0,4,5,6],
    [1,2,3,4,0,6],
    [1,2,3,4,5,6],
    ]
    """
    
    data_arr = [[1,2,3,4,5,6],
    [1,2,0,4,5,6],
    [1,2,3,0,0,6],
    [1,2,3,4,5,6],
    ]
    #
    index_r = []
    index_c = []
    for i, v in enumerate(data_arr):
        for j, n in enumerate(v):
            if n == 0:
                index_r.append(i)
                index_c.append(j)
    new_list = []
    for i, v in enumerate(data_arr):
        new_cloum = []
        for j, n in enumerate(v):
            if i in index_r:
                new_cloum.append(0)
            elif j in index_c:
                new_cloum.append(0)
            else:
                new_cloum.append(n)
        new_list.append(new_cloum)
    print(new_list)
    
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:无聊~更改数组数据状态, 记录,待优化

          本文链接:https://www.haomeiwen.com/subject/xbaypltx.html