Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.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

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 使用if和else条件创建列表 对于总平均值中的tup: 如果tup>=12,tup=49,tup=58,tup=79,tup_Python_List - Fatal编程技术网

Python 使用if和else条件创建列表 对于总平均值中的tup: 如果tup>=12,tup=49,tup=58,tup=79,tup

Python 使用if和else条件创建列表 对于总平均值中的tup: 如果tup>=12,tup=49,tup=58,tup=79,tup,python,list,Python,List,你在找这样的东西 for tup in totalMean: if tup >= 12 and tup <=33: print tup(list) elif tup >= 49 and tup <=52: print tup elif tup >= 58 and tup <=67: print tup elif tup >= 79 and tup <=98:

你在找这样的东西

for tup in totalMean:
    if tup >= 12 and tup <=33:
        print tup(list)
    elif tup >= 49 and tup <=52:
        print tup   
    elif tup >= 58 and tup <=67:
        print tup
    elif tup >= 79 and tup <=98:
        print tup 

希望这能有所帮助。

听起来像是在尝试将值排序到不同的范围:

[[33, 12], [52, 51, 49], [67, 58], [98, 91, 89, 82, 79]]

请详细说明你的问题。为了更好地理解。。还包括您的源数据、预期输出和任何需要的上下文信息。我需要将结果输出到类似于[33,12][52,51,49][67,58][98,91,89,82,79]的列表中。到目前为止,我得到的输出格式如下12 33 49 51 52 58 67 79 82 89 91 98我是编程新手..我尝试了附加,拉链等,但它没有为我工作。我不知道如何实现它。我有一个列表,比如totalMean=[98,91,89,82,79,67,58,52,51,49,33,12]澄清一下,您希望将结果存储到一个列表中,其中内部列表包含给定范围内的整数。是吗?是的。如果我有一个数字totalMean=[98,91,89,82,79,67,58,52,51,49,33,12]的列表,我需要得到[33,12]或[12,33]中的结果,但我得到的结果是[12,33],这肯定有帮助。多谢各位
[[33, 12], [52, 51, 49], [67, 58], [98, 91, 89, 82, 79]]
totalMean = [33, 12, 52, 51, 49, 67, 58, 98, 91, 89, 82, 79]
buckets = {limits: [] for limits in ((12, 33), (49, 52), (58, 67), (79, 98))}

for tup in totalMean:
    for lo, hi in buckets:
        if lo <= tup <= hi:
            buckets[(lo, hi)].append(tup)
            break

result = [sorted(buckets[limits]) for limits in sorted(buckets)]
print(result)