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

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

      <legend id='KCK4z'><style id='KCK4z'><dir id='KCK4z'><q id='KCK4z'></q></dir></style></legend>
      1. <tfoot id='KCK4z'></tfoot>
      2. 在 Python 中使用多个 NOT IN 语句

        Using multiple NOT IN statements with Python(在 Python 中使用多个 NOT IN 语句)

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

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

              <tbody id='lfhPF'></tbody>

                • <bdo id='lfhPF'></bdo><ul id='lfhPF'></ul>
                  本文介绍了在 Python 中使用多个 NOT IN 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要从一个循环中取出带有三个特定子字符串的 URL.以下代码有效,但我确信有一种更优雅的方法:

                  I need to URLs with three specific specific substrings out of a loop. The following code worked, but I am sure there's a more elegant way to do it:

                  for node in soup.findAll('loc'):
                      url = node.text.encode("utf-8")
                      if "/store/" not in url and "/cell-phones/" not in url and "/accessories/" not in url:
                          objlist.loc.append(url) 
                      else:
                          continue
                  

                  谢谢!

                  推荐答案

                  url = node.text.encode("utf-8")    
                  sub_strings = ['/store','/cell-phones/','accessories']
                  
                  if not any(x in url for x in sub_strings):
                      objlist.loc.append(url)
                  else:
                      continue
                  

                  来自 docs:

                  any 返回 True.如果可迭代对象为空,则返回 False.相当于:

                  any returns True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:

                  def any(iterable):
                      for element in iterable:
                          if element:
                              return True
                      return False
                  

                  这篇关于在 Python 中使用多个 NOT IN 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 与否?)
                  <tfoot id='NTn8t'></tfoot>

                    <tbody id='NTn8t'></tbody>

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

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

                        • <bdo id='NTn8t'></bdo><ul id='NTn8t'></ul>
                          <legend id='NTn8t'><style id='NTn8t'><dir id='NTn8t'><q id='NTn8t'></q></dir></style></legend>