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

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

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

        检查 Python 列表中是否有(不)某些东西

        Check if something is (not) in a list in Python(检查 Python 列表中是否有(不)某些东西)
        • <bdo id='EcHuO'></bdo><ul id='EcHuO'></ul>

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

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

                  <tfoot id='EcHuO'></tfoot>

                • 本文介绍了检查 Python 列表中是否有(不)某些东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 Python 中的元组列表,并且我有一个条件仅当元组不在列表中时,我才想采用分支(如果它在列表中,那么我不想采用 if 分支)

                  I have a list of tuples in Python, and I have a conditional where I want to take the branch ONLY if the tuple is not in the list (if it is in the list, then I don't want to take the if branch)

                  if curr_x -1 > 0 and (curr_x-1 , curr_y) not in myList: 
                  
                      # Do Something
                  

                  不过,这对我来说并不适用.我做错了什么?

                  This is not really working for me though. What have I done wrong?

                  推荐答案

                  错误可能在代码中的其他地方,因为它应该可以正常工作:

                  The bug is probably somewhere else in your code, because it should work fine:

                  >>> 3 not in [2, 3, 4]
                  False
                  >>> 3 not in [4, 5, 6]
                  True
                  

                  或者使用元组:

                  >>> (2, 3) not in [(2, 3), (5, 6), (9, 1)]
                  False
                  >>> (2, 3) not in [(2, 7), (7, 3), "hi"]
                  True
                  

                  这篇关于检查 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 与否?)
                    <tbody id='3ylQI'></tbody>
                  <i id='3ylQI'><tr id='3ylQI'><dt id='3ylQI'><q id='3ylQI'><span id='3ylQI'><b id='3ylQI'><form id='3ylQI'><ins id='3ylQI'></ins><ul id='3ylQI'></ul><sub id='3ylQI'></sub></form><legend id='3ylQI'></legend><bdo id='3ylQI'><pre id='3ylQI'><center id='3ylQI'></center></pre></bdo></b><th id='3ylQI'></th></span></q></dt></tr></i><div id='3ylQI'><tfoot id='3ylQI'></tfoot><dl id='3ylQI'><fieldset id='3ylQI'></fieldset></dl></div>
                • <tfoot id='3ylQI'></tfoot>

                      <legend id='3ylQI'><style id='3ylQI'><dir id='3ylQI'><q id='3ylQI'></q></dir></style></legend>
                        <bdo id='3ylQI'></bdo><ul id='3ylQI'></ul>

                        <small id='3ylQI'></small><noframes id='3ylQI'>