<?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 Re: Remove shapefiles from a list in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/remove-shapefiles-from-a-list/m-p/102517#M3976</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jonathan, it worked now, this is helpful. By the way why I cannot see " Mark as correct answer" icon next to your answer!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Jun 2017 12:32:00 GMT</pubDate>
    <dc:creator>AhmadSALEH1</dc:creator>
    <dc:date>2017-06-28T12:32:00Z</dc:date>
    <item>
      <title>Remove shapefiles from a list</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/remove-shapefiles-from-a-list/m-p/102515#M3974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to write the following python script which r&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;emoves all shapefiles (any word that ends with .shp) from a&amp;nbsp;list&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;#Assign variables to the shapefiles&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;park="Parks_sd.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;sewer="Sewer_Main_sd.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;water="water"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;street="street"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;#Create a list of shapefile variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;datalist=[park,sewer,water,street]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;# prints the list before the loop to compare the results&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;print datalist&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;&amp;nbsp; &amp;nbsp; for x in datalist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if x.endswith(".shp"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; datalist.remove(x)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000;"&gt;print datalist&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the result looks like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;['Parks_sd.shp', 'Sewer_Main_sd.shp', 'water', 'street']&lt;BR /&gt;['Sewer_Main_sd.shp', 'water', 'street']&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the code succeeds to remove the first item in the list but fails to remove the second one!&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/358979_py.JPG" style="width: 620px; height: 438px;" /&gt;&lt;/P&gt;&lt;P&gt;What might be the issue here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jun 2017 22:01:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/remove-shapefiles-from-a-list/m-p/102515#M3974</guid>
      <dc:creator>AhmadSALEH1</dc:creator>
      <dc:date>2017-06-27T22:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Remove shapefiles from a list</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/remove-shapefiles-from-a-list/m-p/102516#M3975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You shouldn't be iterating through a list while modifying it. &amp;nbsp;See the following posts:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://stackoverflow.com/questions/6022764/python-removing-list-element-while-iterating-over-list" title="https://stackoverflow.com/questions/6022764/python-removing-list-element-while-iterating-over-list" rel="nofollow noopener noreferrer" target="_blank"&gt;Python: Removing list element while iterating over list - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://stackoverflow.com/questions/7573115/delete-item-from-list-in-python-while-iterating-over-it" title="https://stackoverflow.com/questions/7573115/delete-item-from-list-in-python-while-iterating-over-it" rel="nofollow noopener noreferrer" target="_blank"&gt;Delete item from list in Python while iterating over it - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://stackoverflow.com/questions/1207406/remove-items-from-a-list-while-iterating" title="https://stackoverflow.com/questions/1207406/remove-items-from-a-list-while-iterating" rel="nofollow noopener noreferrer" target="_blank"&gt;python - Remove items from a list while iterating - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do this instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;#Assign variables to the shapefiles&lt;/SPAN&gt;
sewer&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Parks_sd.shp"&lt;/SPAN&gt;
park&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Sewer_Main.shp"&lt;/SPAN&gt;
water&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"water"&lt;/SPAN&gt;
street&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"street"&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#Create a list of shapefile variables&lt;/SPAN&gt;
datalist&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;park&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;sewer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;water&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;street&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; x &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; list&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;datalist&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; x&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;endswith&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;".shp"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalist&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;remove&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;x&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;datalist&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:19:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/remove-shapefiles-from-a-list/m-p/102516#M3975</guid>
      <dc:creator>JonathanQuinn</dc:creator>
      <dc:date>2021-12-11T06:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Remove shapefiles from a list</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/remove-shapefiles-from-a-list/m-p/102517#M3976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jonathan, it worked now, this is helpful. By the way why I cannot see " Mark as correct answer" icon next to your answer!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jun 2017 12:32:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/remove-shapefiles-from-a-list/m-p/102517#M3976</guid>
      <dc:creator>AhmadSALEH1</dc:creator>
      <dc:date>2017-06-28T12:32:00Z</dc:date>
    </item>
  </channel>
</rss>

