我有一个列表列表,我不知道主列表的长度,但每个'子列表'必须包含6个浮点数.我需要比较每个子列表的每个浮点数,并保持较小的一个用于前三个浮点数,而较高的一个用于最后三个浮点数,最后,我需要以相同的顺序在6浮点列表中返回所有这些值.
这是一个例子:
list1 = [[-2.0, 0.0, -2.0, 2.0, 10.0, 2.0], [-1.0, 0.0, 2.0, 1.0, 5.0, 4.0]]
# Compare list1[0][0] with list1[1][0]
# Will return -2.0 (because the index is between 0 and 2 so it returns the lower float)
# Compare list1[0][4] with list1[1][4]
# Will return 10.0 (because the index is between 3 and 5 so it returns the higher float)
# The final result which should be returned is:
# [-2.0, 0.0, -2.0, 2.0, 10.0, 4.0]
list2 = …
Run Code Online (Sandbox Code Playgroud)