如何列出各种值的列表

时间:2014-07-23 23:03:12

标签: python list sorting variables bin

我的问题解释得非常糟糕,但我会尝试用例子来解释:

所以基本上现在我将数据分类到箱子中并使箱子计算数据点适合它的次数。

输出如下:

[8.8000000000000007, 8.9000000000000004, 143.37965848278122], [8.9000000000000004, 9.0, 0.0], [9.0, 9.0999999999999996, 0.0], [9.0999999999999996, 9.2000000000000011, 0.0], [9.2000000000000011, 9.3000000000000007, 408.47433288806104], [9.3000000000000007, 9.4000000000000004, 0.0], [9.4000000000000004, 9.5, 0.0], [9.5, 9.6000000000000014, 0.0], [9.6000000000000014, 9.7000000000000011, 0.0], [9.7000000000000011, 9.8000000000000007, 0.0], [9.8000000000000007, 9.9000000000000004, 0.0], [9.9000000000000004, 10.0, 222.80941832818451], [10.0, 10.100000000000001, 0.0], [10.100000000000001, 10.200000000000001, 0.0], [10.200000000000001, 10.300000000000001, 52.353134616482727], [10.300000000000001, 10.4, 0.0], [10.4, 10.5, 0.0], [10.5, 10.600000000000001, 185.14613546955295], [10.600000000000001, 10.700000000000001, 0.0], [10.700000000000001, 10.800000000000001, 0.0], [10.800000000000001, 10.9, 107.72261969214365], [10.9, 11.0, 0.0], [11.0, 11.100000000000001, 0.0], [11.100000000000001, 11.200000000000001, 240.18540705353223], [11.200000000000001, 11.300000000000001, 0.0], [11.300000000000001, 11.4, 0.0], [11.4, 11.5, 81.578491590135258], [11.5, 11.600000000000001, 0.0], [11.600000000000001, 11.700000000000001, 0.0], [11.700000000000001, 11.800000000000001, 136.94879576505122], [11.800000000000001, 11.9, 0.0], [11.9, 12.0, 65.532858620056061], [12.0, 12.100000000000001, 0.0], [12.100000000000001, 12.200000000000001, 0.0], [12.200000000000001, 12.300000000000001, 124.08846270524724], [12.300000000000001, 12.4, 0.0], [12.4, 12.5, 0.0], [12.5, 12.600000000000001, 17.461201349990102], [12.600000000000001, 12.700000000000001, 0.0], [12.700000000000001, 12.800000000000001, 192.67378539948248], [12.800000000000001, 12.9, 0.0], [12.9, 13.0, 0.0], [13.0, 13.100000000000001, 53.829391020482625], [13.100000000000001, 13.200000000000001, 0.0], [13.200000000000001, 13.300000000000001, 194.83328164196993], [13.300000000000001, 13.4, 0.0], [13.4, 13.5, 0.0], [13.5, 13.600000000000001, 87.377598066432199], [13.600000000000001, 13.700000000000001, 0.0], [13.700000000000001, 13.800000000000001, 47.27591250219281], [13.800000000000001, 13.9, 0.0], [13.9, 14.0, 0.0], [14.0, 14.100000000000001, 0.0], [14.100000000000001, 14.200000000000001, 0.0], [14.200000000000001, 14.300000000000001, 154.62214008681087], [14.300000000000001, 14.4, 0.0], [14.4, 14.5, 11.707762931107476], [14.5, 14.600000000000001, 0.0], [14.600000000000001, 14.700000000000001, 144.42519475942709], [14.700000000000001, 14.800000000000001, 0.0], [14.800000000000001, 14.9, 0.0], [14.9, 15.0, 69.044443552750224], [15.0, 15.100000000000001, 0.0], [15.100000000000001, 15.200000000000001, 59.495014815982941], [15.200000000000001, 15.300000000000001, 0.0], [15.300000000000001, 15.4, 47.984921515624045], [15.4, 15.5, 0.0], [15.5, 15.600000000000001, 148.33194183377037], [15.600000000000001, 15.700000000000001, 0.0], [15.700000000000001, 15.800000000000001, 26.946778147482402], [15.800000000000001, 15.9, 0.0], [15.9, 16.0, 52.02496718145369], [16.0, 16.100000000000001, 0.0], [16.100000000000001, 16.199999999999999, 28.118112302101068], [16.199999999999999, 16.300000000000001, 0.0], [16.300000000000001, 16.400000000000002, 54.154395888749733], [16.400000000000002, 16.5, 0.0], [16.5, 16.600000000000001, 46.856876310111147], [16.600000000000001, 16.699999999999999, 0.0], [16.699999999999999, 16.800000000000001, 116.5738245865068], [16.800000000000001, 16.900000000000002, 0.0], [16.900000000000002, 17.0, 19.942608687594863], [17.0, 17.100000000000001, 0.0], [17.100000000000001, 17.199999999999999, 105.06314953163738], [17.199999999999999, 17.300000000000001, 0.0], [17.300000000000001, 17.400000000000002, 0.0], [17.400000000000002, 17.5, 0.0], [17.5, 17.600000000000001, 75.773468431043554], [17.600000000000001, 17.699999999999999, 0.0], [17.699999999999999, 17.800000000000001, 17.458060812924451], [17.800000000000001, 17.900000000000002, 81.759489528780122], [17.900000000000002, 18.0, 0.0], [18.0, 18.100000000000001, 24.385922261321497], [18.100000000000001, 18.199999999999999, 0.0], [18.199999999999999, 18.300000000000001, 35.60952279109361], [18.300000000000001, 18.400000000000002, 0.0], [18.400000000000002, 18.5, 50.270775299596309], [18.5, 18.600000000000001, 0.0], [18.600000000000001, 18.699999999999999, 46.892192113002331], [18.699999999999999, 18.800000000000001, 20.498542196856238], [18.800000000000001, 18.900000000000002, 0.0], [18.900000000000002, 19.0, 86.105083060247352], [19.0, 19.100000000000001, 0.0], [19.100000000000001, 19.200000000000003, 0.0], [19.200000000000003, 19.300000000000001, 52.82783329964937], [19.300000000000001, 19.400000000000002, 0.0], [19.400000000000002, 19.5, 38.772377251090269], [19.5, 19.600000000000001, 0.0], [19.600000000000001, 19.700000000000003, 38.506491320506335], [19.700000000000003, 19.800000000000001, 0.0], [19.800000000000001, 19.900000000000002, 24.429240971002859], [19.900000000000002, 20.0, 59.022796124870681]]

每个元组中的第三个数字是使用bin的次数。

但现在我想创建列表中所有“第3”点的列表。

我不确定如何仅隔离每个元组的特定方面。

我是一名初学程序员,所以这可能非常基础,但我一直坚持这一点,所以任何反馈都会受到赞赏。

2 个答案:

答案 0 :(得分:3)

my_3rd_points = [point[2] for point in a_list_of_tuples]

我认为应该工作

或者如果它们总是3宽,你可以将它们解压缩成变量

my_3rd_points = [third for first,second,third in a_list_of_tuples]

或者如果你想要,使用mapoperator.itemgetter

可能会很棘手

答案 1 :(得分:1)

在列表推导中使用索引

thirds = [i[2] for i in l]

您的列表在l。然后thirds将是:

[143.37965848278122, 0.0, 0.0, 0.0, 408.47433288806104, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 222.8094183281845, 0.0, 0.0, 52.35313461648273, 0.0, 0.0, 185.14613546955295, 0.0, 0.0, 107.72261969214365, 0.0, 0.0, 240.18540705353223, 0.0, 0.0, 81.57849159013526, 0.0, 0.0, 136.94879576505122, 0.0, 65.53285862005606, 0.0, 0.0, 124.08846270524724, 0.0, 0.0, 17.4612013499901, 0.0, 192.67378539948248, 0.0, 0.0, 53.829391020482625, 0.0, 194.83328164196993, 0.0, 0.0, 87.3775980664322, 0.0, 47.27591250219281, 0.0, 0.0, 0.0, 0.0, 154.62214008681087, 0.0, 11.707762931107476, 0.0, 144.4251947594271, 0.0, 0.0, 69.04444355275022, 0.0, 59.49501481598294, 0.0, 47.984921515624045, 0.0, 148.33194183377037, 0.0, 26.9467781474824, 0.0, 52.02496718145369, 0.0, 28.118112302101068, 0.0, 54.15439588874973, 0.0, 46.85687631011115, 0.0, 116.5738245865068, 0.0, 19.942608687594863, 0.0, 105.06314953163738, 0.0, 0.0, 0.0, 75.77346843104355, 0.0, 17.45806081292445, 81.75948952878012, 0.0, 24.385922261321497, 0.0, 35.60952279109361, 0.0, 50.27077529959631, 0.0, 46.89219211300233, 20.49854219685624, 0.0, 86.10508306024735, 0.0, 0.0, 52.82783329964937, 0.0, 38.77237725109027, 0.0, 38.506491320506335, 0.0, 24.42924097100286, 59.02279612487068]