我有一个列表,其中包含了多个子列表,我不知道主列表的长度,但是每个子列表都包含了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 = [[-2.0, 0.0, -2.0, 2.0, 10.0, 2.0], [-1.0, 0.0, 2.0, 1.0, 5.0, 4.0], [3.0, 0.0, -1.0, 4.0, 1.0, 0.0]]
# Compare list2[0][2] with list2[1][2] with list2[2][2]
# Will return -2.0 (because the index is between 0 and 2 so it returns the lower float)
# The final result which should be returned is:
# [-2.0, 0.0, -2.0, 4.0, 10.0, 4.0]
我在这个网站上阅读了有关zip()
、集合、列表推导式以及其他不同主题的内容,但是我无法实现我想要的功能。