Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
浮点数集,将数以集合形式附加到空列表中。python_Python_List_Function_Append_Max - Fatal编程技术网

浮点数集,将数以集合形式附加到空列表中。python

浮点数集,将数以集合形式附加到空列表中。python,python,list,function,append,max,Python,List,Function,Append,Max,一组数字 n_set = [1.0,3.2,4.5,8.2,1.3,2.2,5.6,9.8,2.4,5.5,6.7] 所以我试图构造一个函数,它接受一组数字,并从数字集中创建一个列表。我试图让每个列表都有一个原始集合中的数字子集,该子集会不断增加,直到达到最大值 organized_set = [[1.0,3.2,4.5,8.2],[1.3,2.2,5.6,9.8],[2.4,5.5,6.7]] 我在想一些关于 for i,k in zip(range(0,len(n_set)),n_set

一组数字

n_set = [1.0,3.2,4.5,8.2,1.3,2.2,5.6,9.8,2.4,5.5,6.7]
所以我试图构造一个函数,它接受一组数字,并从数字集中创建一个列表。我试图让每个列表都有一个原始集合中的数字子集,该子集会不断增加,直到达到最大值

organized_set = [[1.0,3.2,4.5,8.2],[1.3,2.2,5.6,9.8],[2.4,5.5,6.7]]
我在想一些关于

for i,k in zip(range(0,len(n_set)),n_set):
    set = []
    d = dict(zip(i,k))
    d2 = dict(zip(k,i))
    if d[i] < d[d2[i]+1]:
        set.append(k)
zip中的i,k(范围(0,len(n_集)),n_集)的
:
set=[]
d=dict(zip(i,k))
d2=dict(zip(k,i))
如果d[i]

这没有道理。我正在处理一个复杂得多的函数,但这是其中的一部分,让我感到厌烦。任何帮助都将不胜感激

尝试以下迭代方法:

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 
python3.2
温度=[]
res=[]
对于n中的i:
临时附加(i)

如果len(temp)>1,那么iAwesome!很有效,非常感谢。我有点搞不清楚有几个部分是怎么工作的。1] 因为“如果x[[1.0, 3.2, 4.5, 8.2], [1.3, 2.2, 5.6, 9.8], [2.4, 5.5, 6.7]]
     python 3.2

     temp=[]
     res=[]

     for i in n:
          temp.append(i)
          if len(temp)>1 and i<temp[-2]:
                  res.append(temp[:-1])
                  temp=[i]
     res.append(temp)
     print(res)