试图在一个列表中找到多个列表的最低值

时间:2016-06-28 18:57:55

标签: list python-2.7

BlocksPerColumn只是整体的一部分,但它仅仅是为了这个想法。

BlocksPerColumn = [[[336350.0, 7089650.0, -7.0, 0.1665, 1.5, 1, 1, 'Ghost', 3, 'Ghost', 'Ghost', 'Ghost', 'Ghost', 2, 'Ghost', 0, -30000.0], [336350.0, 7089650.0, -5.0, 0.1542, 1.5, 1, 2, 'Ghost', 3, 'Ghost', 'Ghost', 'Ghost', 'Ghost', 2, 'Ghost', 0, -30000.0], [336350.0, 7089650.0, -3.0, 0.2259, 1.5, 1, 3, 'Ghost', 3, 'Ghost', 'Ghost', 'Ghost', 'Ghost', 2, 'Ghost', 1, 153475.49999999997], [336350.0, 7089650.0, -1.0, 0.2753, 1.5, 1, 4, 'Ghost', 3, 'Ghost', 'Ghost', 'Ghost', 'Ghost', 2, 'Ghost', 1, 200158.49999999997], [336350.0, 7089650.0, 1.0, 0.2236, 1.5, 1, 5, 'Ghost', 3, 'Ghost', 'Ghost', 'Ghost', 'Ghost', 2, 'Ghost', 1, 151301.99999999997]], [[336450.0, 7089550.0, -7.0, 0.1791, 1.5, 2, 6, 3, 6, 'Ghost', 'Ghost', 1, 7, 5, 'Ghost', 0, -30000.0], [336450.0, 7089550.0, -5.0, 0.1707, 1.5, 2, 7, 3, 6, 'Ghost', 'Ghost', 1, 7, 5, 'Ghost', 0, -30000.0], [336450.0, 7089550.0, -3.0, 0.2248, 1.5, 2, 8, 3, 6, 'Ghost', 'Ghost', 1, 7, 5, 'Ghost', 1, 152436.0], [336450.0, 7089550.0, -1.0, 0.2791, 1.5, 2, 9, 3, 6, 'Ghost', 'Ghost', 1, 7, 5, 'Ghost', 1, 203749.5], [336450.0, 7089550.0, 1.0, 0.3098, 1.5, 2, 10, 3, 6, 'Ghost', 'Ghost', 1, 7, 5, 'Ghost', 1, 232760.99999999994]], [[336450.0, 7089650.0, -5.0, 0.1488, 1.5, 3, 11, 'Ghost', 7, 2, 1, 'Ghost', 'Ghost', 6, 'Ghost', 0, -30000.0], [336450.0, 7089650.0, -3.0, 0.1961, 1.5, 3, 12, 'Ghost', 7, 2, 1, 'Ghost', 'Ghost', 6, 'Ghost', 0, -30000.0], [336450.0, 7089650.0, -1.0, 0.2499, 1.5, 3, 13, 'Ghost', 7, 2, 1, 'Ghost', 'Ghost', 6, 'Ghost', 1, 176155.5], [336450.0, 7089650.0, 1.0, 0.2939, 1.5, 3, 14, 'Ghost', 7, 2, 1, 'Ghost', 'Ghost', 6, 'Ghost', 1, 217735.5]], [[336550.0, 7089350.0, -7.0, 0.1774, 1.5, 4, 15, 5, 10, 'Ghost', 'Ghost', 'Ghost', 11, 9, 'Ghost', 0, -30000.0], [336550.0, 7089350.0, -5.0, 0.2551, 1.5, 4, 16, 5, 10, 'Ghost', 'Ghost', 'Ghost', 11, 9, 'Ghost', 1, 181069.5], [336550.0, 7089350.0, -3.0, 0.3489, 1.5, 4, 17, 5, 10, 'Ghost', 'Ghost', 'Ghost', 11, 9, 'Ghost', 1, 269710.49999999994], [336550.0, 7089350.0, -1.0, 0.3707, 1.5, 4, 18, 5, 10, 'Ghost', 'Ghost', 'Ghost', 11, 9, 'Ghost', 1, 290311.5], [336550.0, 7089350.0, 1.0, 0.3037, 1.5, 4, 19, 5, 10, 'Ghost', 'Ghost', 'Ghost', 11, 9, 'Ghost', 1, 226996.5]], [[336550.0, 7089450.0, -5.0, 0.1719, 1.5, 5, 20, 6, 11, 4, 'Ghost', 2, 12, 10, 'Ghost', 0, -30000.0], [336550.0, 7089450.0, -3.0, 0.3121, 1.5, 5, 21, 6, 11, 4, 'Ghost', 2, 12, 10, 'Ghost', 1, 234934.5], [336550.0, 7089450.0, -1.0, 0.3491, 1.5, 5, 22, 6, 11, 4, 'Ghost', 2, 12, 10, 'Ghost', 1, 269899.49999999994], [336550.0, 7089450.0, 1.0, 0.326, 1.5, 5, 23, 6, 11, 4, 'Ghost', 2, 12, 10, 'Ghost', 1, 248070.0]], [[336550.0, 7089550.0, -7.0, 0.1494, 1.5, 6, 24, 7, 12, 5, 2, 3, 13, 11, 'Ghost', 0, -30000.0], [336550.0, 7089550.0, -5.0, 0.1598, 1.5, 6, 25, 7, 12, 5, 2, 3, 13, 11, 'Ghost', 0, -30000.0], [336550.0, 7089550.0, -3.0, 0.2061, 1.5, 6, 26, 7, 12, 5, 2, 3, 13, 11, 'Ghost', 1, 134764.5], [336550.0, 7089550.0, -1.0, 0.2554, 1.5, 6, 27, 7, 12, 5, 2, 3, 13, 11, 'Ghost', 1, 181353.0], [336550.0, 7089550.0, 1.0, 0.3218, 1.5, 6, 28, 7, 12, 5, 2, 3, 13, 11, 'Ghost', 1, 244101.0]], [[336550.0, 7089650.0, -5.0, 0.1334, 1.5, 7, 29, 'Ghost', 13, 6, 3, 'Ghost', 'Ghost', 12, 2, 0, -30000.0], [336550.0, 7089650.0, -3.0, 0.1711, 1.5, 7, 30, 'Ghost', 13, 6, 3, 'Ghost', 'Ghost', 12, 2, 0, -30000.0], [336550.0, 7089650.0, -1.0, 0.193, 1.5, 7, 31, 'Ghost', 13, 6, 3, 'Ghost', 'Ghost', 12, 2, 0, -30000.0], [336550.0, 7089650.0, 1.0, 0.2498, 1.5, 7, 32, 'Ghost', 13, 6, 3, 'Ghost', 'Ghost', 12, 2, 1, 176061.0]]]

Deepest_Block_All_Columns = [] # Will have the lowest Z-value for each column.
        for item in range(0,len(BlocksPerColumn)):
            Deepest_Block_Column = [100] # Making sure that the z value at start is always lower.
            for i in range(0,len(BlocksPerColumn[item])):
                if BlocksPerColumn[item][i][2] < Deepest_Block_Column:
                    Deepest_Block_Column = BlocksPerColumn[item][i][2]
            Deepest_Block_All_Columns += [Deepest_Block_Column]
            Deepest_Block_Column = [100]
        print Deepest_Block_All_Columns

结果我收到了:

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

为什么我没有得到-7.0(因为-7.0是最低的),为什么我收到0&#39;

[[-7.0],[ -7.0]........]

我希望每个项目的索引2的最低值(这是一个z坐标)。

1 个答案:

答案 0 :(得分:1)

首先,你不会得到一个列表列表。因为无论何时添加两个列表,结果都将是合并列表。 要获得列表,您应该Deepest_Block_All_Columns.append([Deepest_Block_Column]) 此外,您的代码段是正确的。我跑的时候给我 [-7.0, -7.0, -5.0, -7.0, -5.0, -7.0, -5.0] 尝试附上如上所示的列表,可能会有所帮助。

注意:这实际上并未回答您的问题 正如我所看到的那样,您将列表作为Deepest_Block_Column进行比较,然后将其作为一个简单变量,因为您已将Deepest_Block_All_Columns作为列表,当您append()该变量时,它将被添加到该变量中名单 所以可能会让这种改变有所帮助。请告诉我这些变化是否有帮助