• <bdo id='SvlL7'></bdo><ul id='SvlL7'></ul>
    <i id='SvlL7'><tr id='SvlL7'><dt id='SvlL7'><q id='SvlL7'><span id='SvlL7'><b id='SvlL7'><form id='SvlL7'><ins id='SvlL7'></ins><ul id='SvlL7'></ul><sub id='SvlL7'></sub></form><legend id='SvlL7'></legend><bdo id='SvlL7'><pre id='SvlL7'><center id='SvlL7'></center></pre></bdo></b><th id='SvlL7'></th></span></q></dt></tr></i><div id='SvlL7'><tfoot id='SvlL7'></tfoot><dl id='SvlL7'><fieldset id='SvlL7'></fieldset></dl></div>
      <tfoot id='SvlL7'></tfoot>
      <legend id='SvlL7'><style id='SvlL7'><dir id='SvlL7'><q id='SvlL7'></q></dir></style></legend>

    1. <small id='SvlL7'></small><noframes id='SvlL7'>

      1. 元组对,使用 python 找到最小值

        Tuple pairs, finding minimum using python(元组对,使用 python 找到最小值)

        <legend id='0gphq'><style id='0gphq'><dir id='0gphq'><q id='0gphq'></q></dir></style></legend><tfoot id='0gphq'></tfoot>
                <tbody id='0gphq'></tbody>
                <bdo id='0gphq'></bdo><ul id='0gphq'></ul>

                <small id='0gphq'></small><noframes id='0gphq'>

                <i id='0gphq'><tr id='0gphq'><dt id='0gphq'><q id='0gphq'><span id='0gphq'><b id='0gphq'><form id='0gphq'><ins id='0gphq'></ins><ul id='0gphq'></ul><sub id='0gphq'></sub></form><legend id='0gphq'></legend><bdo id='0gphq'><pre id='0gphq'><center id='0gphq'></center></pre></bdo></b><th id='0gphq'></th></span></q></dt></tr></i><div id='0gphq'><tfoot id='0gphq'></tfoot><dl id='0gphq'><fieldset id='0gphq'></fieldset></dl></div>

                • 本文介绍了元组对,使用 python 找到最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想找到按给定列排序的元组列表的最小值.例如,我将一些数据排列为 2 元组列表.

                  I want to find the minimum of a list of tuples sorting by a given column. I have some data arranged as a list of 2-tuples for example.

                  data = [ (1, 7.57), (2, 2.1), (3, 1.2), (4, 2.1), (5, 0.01), 
                           (6, 0.5), (7, 0.2), (8, 0.6)]
                  

                  如何仅通过比较元组中的第二个数字来找到数据集的最小值?

                  How may I find the min of the dataset by the comparison of the second number in the tuples only?

                  data[0][1] = 7.57
                  data[1][1] = 2.1
                  

                  min( 数据 ) = (5, 0.01)

                  min( data ) = (5, 0.01)

                  min(data) 返回 (1, 7.57),我接受它对于索引 0 的最小值是正确的,但我想要索引 1 的最小值.

                  min( data ) returns (1, 7.57), which I accept is correct for the minimum of index 0, but I want minimum of index 1.

                  推荐答案

                  In [2]: min(data, key = lambda t: t[1])
                  Out[2]: (5, 0.01)
                  

                  或:

                  In [3]: import operator
                  
                  In [4]: min(data, key=operator.itemgetter(1))
                  Out[4]: (5, 0.01)
                  

                  这篇关于元组对,使用 python 找到最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

                      • <bdo id='azO2E'></bdo><ul id='azO2E'></ul>
                          <tbody id='azO2E'></tbody>
                        <i id='azO2E'><tr id='azO2E'><dt id='azO2E'><q id='azO2E'><span id='azO2E'><b id='azO2E'><form id='azO2E'><ins id='azO2E'></ins><ul id='azO2E'></ul><sub id='azO2E'></sub></form><legend id='azO2E'></legend><bdo id='azO2E'><pre id='azO2E'><center id='azO2E'></center></pre></bdo></b><th id='azO2E'></th></span></q></dt></tr></i><div id='azO2E'><tfoot id='azO2E'></tfoot><dl id='azO2E'><fieldset id='azO2E'></fieldset></dl></div>

                          <small id='azO2E'></small><noframes id='azO2E'>

                        • <tfoot id='azO2E'></tfoot>
                          <legend id='azO2E'><style id='azO2E'><dir id='azO2E'><q id='azO2E'></q></dir></style></legend>