<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Query with a list in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/query-with-a-list/m-p/1559305#M73199</link>
    <description>&lt;P&gt;I have features in a class &lt;STRONG&gt;fc&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I want to take the list of BuildingKeys and run a query to delete those from a different feature &lt;STRONG&gt;hosted_feature&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc, [BuildingKey]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;variable = "'" + str(row[0]) + "'"&lt;BR /&gt;buildingkey = "BuildingKey = "&lt;BR /&gt;query = buildingkey + variable&lt;BR /&gt;deleted = hosted_feature.delete_features(where = query)&lt;/P&gt;&lt;P&gt;Right now it loops through and deletes each one individually.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If instead of looping, how would I just get the entire list of BuildingKeys and put that in the query?&lt;/LI&gt;&lt;LI&gt;Would it be 'includes'?&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Fri, 15 Nov 2024 18:27:46 GMT</pubDate>
    <dc:creator>CW-GIS</dc:creator>
    <dc:date>2024-11-15T18:27:46Z</dc:date>
    <item>
      <title>Query with a list</title>
      <link>https://community.esri.com/t5/python-questions/query-with-a-list/m-p/1559305#M73199</link>
      <description>&lt;P&gt;I have features in a class &lt;STRONG&gt;fc&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I want to take the list of BuildingKeys and run a query to delete those from a different feature &lt;STRONG&gt;hosted_feature&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc, [BuildingKey]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;variable = "'" + str(row[0]) + "'"&lt;BR /&gt;buildingkey = "BuildingKey = "&lt;BR /&gt;query = buildingkey + variable&lt;BR /&gt;deleted = hosted_feature.delete_features(where = query)&lt;/P&gt;&lt;P&gt;Right now it loops through and deletes each one individually.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If instead of looping, how would I just get the entire list of BuildingKeys and put that in the query?&lt;/LI&gt;&lt;LI&gt;Would it be 'includes'?&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 15 Nov 2024 18:27:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-with-a-list/m-p/1559305#M73199</guid>
      <dc:creator>CW-GIS</dc:creator>
      <dc:date>2024-11-15T18:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Query with a list</title>
      <link>https://community.esri.com/t5/python-questions/query-with-a-list/m-p/1559348#M73200</link>
      <description>&lt;P&gt;maybe something like this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

# Collect all BuildingKeys into list, excluding empty, blank, or null values
building_keys = []
with arcpy.da.SearchCursor(fc, ["BuildingKey"]) as cursor:
    for row in cursor:
        building_key = row[0]
        if building_key and str(building_key).strip():  # Check for non-empty, non-null, non-blank values
            building_keys.append("'" + str(building_key) + "'") #building_keys.append(str(row[0])) 

# Only proceed if there are valid BuildingKeys
if building_keys:
    # Create a query string using IN 
    query = "BuildingKey IN ({})".format(", ".join(building_keys))

    # Delete features using the query
    deleted = hosted_feature.delete_features(where=query)
else:
    print("No valid BuildingKeys to delete.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 19:30:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-with-a-list/m-p/1559348#M73200</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-11-15T19:30:41Z</dc:date>
    </item>
  </channel>
</rss>

