Hello,
I am trying to write the following python script which removes all shapefiles (any word that ends with .shp) from a list
#Assign variables to the shapefiles
park="Parks_sd.shp"
sewer="Sewer_Main_sd.shp"
water="water"
street="street"
#Create a list of shapefile variables
datalist=[park,sewer,water,street]
# prints the list before the loop to compare the results
print datalist
for x in datalist:
if x.endswith(".shp"):
datalist.remove(x)
print datalist
But the result looks like this
['Parks_sd.shp', 'Sewer_Main_sd.shp', 'water', 'street']
['Sewer_Main_sd.shp', 'water', 'street']
the code succeeds to remove the first item in the list but fails to remove the second one!
What might be the issue here?