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

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

    • <bdo id='G7M0d'></bdo><ul id='G7M0d'></ul>

      1. 元组键值

        Tuple value by key(元组键值)
            • <bdo id='vDSep'></bdo><ul id='vDSep'></ul>
              <tfoot id='vDSep'></tfoot>

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

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

                  <tbody id='vDSep'></tbody>

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

                  问题描述

                  是否可以从元组中获取价值:

                  Is it possible to get Value out of tuple:

                  TUPLE = (
                      ('P', 'Shtg1'),
                      ('R', u'Shtg2'),
                      ('D', 'Shtg3'),
                  )
                  

                  通过调用像 P

                  Python 说只有 int 可以用于这种类型的查询"

                  Python says that only int can be used for this type of 'query'

                  我不能使用循环(开销太大...)

                  I can't use loop (too much overhead...)

                  谢谢!

                  推荐答案

                  此类查询的规范数据结构是字典:

                  The canonical data structure for this type of queries is a dictionary:

                  In [1]: t = (
                     ...:     ('P', 'Shtg1'),
                     ...:     ('R', u'Shtg2'),
                     ...:     ('D', 'Shtg3'),
                     ...: )
                  
                  In [2]: d = dict(t)
                  
                  In [3]: d['P']
                  Out[3]: 'Shtg1'
                  

                  如果使用元组,则无法避免循环(显式或隐式).

                  If you use a tuple, there is no way to avoid looping (either explicit or implicit).

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

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

                  相关文档推荐

                  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 与否?)

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

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

                        <tbody id='tYlSU'></tbody>

                      <legend id='tYlSU'><style id='tYlSU'><dir id='tYlSU'><q id='tYlSU'></q></dir></style></legend>

                        1. <tfoot id='tYlSU'></tfoot>
                            <bdo id='tYlSU'></bdo><ul id='tYlSU'></ul>