nodes = set([(2,1,2,1),(2, 1, 2, 2),(2, 1, 3, 2),(3, 1, 4, 1),(3, 5, 5, 1)])
nodes_max_time = filter(lambda x: x[2] == max(map(lambda z: z[2], filter(lambda y: y[0] == x[0] and y[1] == x[1], nodes))), nodes)
nodes_max_time1 = filter(lambda x: x[3] == max(map(lambda z: z[3], filter(lambda y: y[0] == x[0] and y[1] == x[1] and y[2] == x[2], nodes))), nodes)
print nodes_max_time
print nodes_max_time1
输出结果:
[(2, 1, 3, 2), (3, 1, 4, 1), (3, 5, 5, 1)]
[(2, 1, 2, 2), (2, 1, 3, 2), (3, 1, 4, 1), (3, 5, 5, 1)]
list之中过滤元组之中前三项相同的,保留第四项数目最大的
最新推荐文章于 2024-07-12 16:16:27 发布