尝试这样的迭代方法:n_set = [1.0,3.2,4.5,8.2,1.3,2.2,5.6,9.8,2.4,5.5,6.7]
prev = None
result = []
current = []
for x in n_set:
if prev is not None and x < prev:
# Next element is smaller than previous element.
# The current group is finished.
result.append(current)
# Start a new group.
current = [x]
else:
# Add the element to the current group.
current.append(x)
# Remember the value of the current element.
prev = x
# Append the last group to the result.
result.append(current)
print result
结果:[[1.0, 3.2, 4.5, 8.2], [1.3, 2.2, 5.6, 9.8], [2.4, 5.5, 6.7]]