<?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: ArcMap10.1 Loop through a unique list to create new layers for each unique name. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328177#M25531</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your quick response. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still getting an error with the SelectLayerByAttribute:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000358: Invalid expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I feel like it has to be the following bolded part: arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", &lt;/SPAN&gt;&lt;STRONG&gt;"Layer = " + name&lt;/STRONG&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Apr 2014 15:38:25 GMT</pubDate>
    <dc:creator>StewartChritton</dc:creator>
    <dc:date>2014-04-10T15:38:25Z</dc:date>
    <item>
      <title>ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328175#M25529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have only taken one GIS class that used python so this is messy! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was able to get the unique list from the attributes table under the column 'Layer'. Next I need the program to use each unique name from that list, select by attributes and create a new layer file for each unique name. I have the count in there because there are 33 different unique names in that list. I know there is a better way to do this, I just don't remember how. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I realize my code is far from perfect so if you have other questions or tips please don't hesitate to ask. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, sys, os, traceback&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fc = r"C:\Users\Drew\Desktop\Montpelier\PythonTest\PythonGDB.gdb\dshline_Project"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;field = ["Layer"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;valueList = []&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Use search cursor to aquire a list of unique values&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, field) as cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valueList.append(row[0])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueSet = set(valueList)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueList = list(uniqueSet)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueList.sort()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = uniqueList[count]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputname = r"C:\Users\Drew\Desktop\Montpelier\PythonTest\PythonGDB.gdb\"" + name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count &amp;lt; 34:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management (r"C:\Users\Drew\Desktop\Montpelier\PythonTest\PythonGDB.gdb\dshline_Project", "layer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("layer","NEW_SELECTION", """Layer" = """ + name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("dshline_Project","NEW_SELECTION",""""Layer" = 'ANNOT'""")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(fc,outputname,"#","0","0","0")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Done"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please Help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 14:50:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328175#M25529</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T14:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328176#M25530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, sys, os, traceback
from arcpy import env
env.workspace = r"C:\Users\Drew\Desktop\Montpelier\PythonTest\PythonGDB.gdb"
env.overwriteOutput = 1

fc = "dshline_Project"
field = ["Layer"]
valueList = []

#Use search cursor to aquire a list of unique values
with arcpy.da.SearchCursor(fc, field) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; valueList.append(row[0])

uniqueSet = set(valueList)
uniqueList = list(uniqueSet)
uniqueList.sort()

del cursor

count = 0
name = uniqueList[count]

if count &amp;lt; 34:
&amp;nbsp;&amp;nbsp;&amp;nbsp; outputname = env.workspace + os.sep + name
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management (fc, "layer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", "Layer = " + name)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("layer", outputname)
&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; name = uniqueList[count]
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Done"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:33:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328176#M25530</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T15:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328177#M25531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your quick response. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still getting an error with the SelectLayerByAttribute:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000358: Invalid expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I feel like it has to be the following bolded part: arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", &lt;/SPAN&gt;&lt;STRONG&gt;"Layer = " + name&lt;/STRONG&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 15:38:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328177#M25531</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T15:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328178#M25532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try the following for the Select function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", &lt;/SPAN&gt;&lt;STRONG&gt;"Layer = '" + name + "'"&lt;/STRONG&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 15:52:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328178#M25532</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2014-04-10T15:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328179#M25533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Partial success!! It created the first file in the list successfully but didn't continue on to do the rest. Something wrong with the way i set up the loop perhaps?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also just noticed that it doesn't print done in the end...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 16:05:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328179#M25533</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T16:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328180#M25534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I just changed the loop to a while loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lencount = len(uniqueList)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while count &amp;lt; lencount:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now it is working but I get an error at the end:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Users\Drew\Desktop\Montpelier\PythonTest\ep2.py", line 41, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = uniqueList[count]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error Info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;list index out of range&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ArcPy ERRORS:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think it keeps trying to go after the loop should close but it already accomplished what I needed so i guess that's fine!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a bunch for you fast replies!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 16:31:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328180#M25534</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T16:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328181#M25535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Glad this is working.&amp;nbsp; Can you mark this forum as answered?&amp;nbsp; It will further help users in the community.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 17:12:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328181#M25535</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2014-04-10T17:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328182#M25536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Of course, I cannot find the button to mark it... one last bit of help please?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 17:23:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328182#M25536</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T17:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328183#M25537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, sloppy it is, and although it finishes maybe you still want to know why it's behaving that way?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's because you make it through the loop on the last member of the list, then increment your index variable (i) and try to set your variable by looking up the value by index - the result is it does not exist because you have in fact exceeded the range, hence the 'out of range' error.&amp;nbsp; The index of a list is zero-based, e.g., your list index with 33 members must advance in the loop from i = 0 to i = 32....in other words, 0 to 32 (including the 0) is 33.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suppose the easiest fix is to modify how you enter the loop:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
while count &amp;lt;= lencount - 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # the rest of your code
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # so that 33 - 1 = 32, the upper index 0-based limit
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:33:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328183#M25537</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T15:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328184#M25538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks! That makes perfect sense.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 20:59:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328184#M25538</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T20:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328185#M25539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;lol, I am sorry, I am mistaken...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually, you only need one 'name = uniqueList[count]' line and you can put that just after your loop begins, as such:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
count = 0
while count &amp;lt; lencount:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = uniqueList[count]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", "Layer = '" + name + "'")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # etc., etc.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1

print 'done!'
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...or, maybe simpler:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for count in range(lencount):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = uniqueList[count]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", "Layer = '" + name + "'")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # etc., etc.

print 'done!'
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry about that (and yes, 'while count &amp;lt;= lencount - 1' would work too).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS - Incidentally, you may end with a 'done!' statement outside of your loop, as shown.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:33:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328185#M25539</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T15:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328186#M25540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again, this time I actually put it in and tested it&amp;nbsp; and everything ran smoothly. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Appreciate it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 21:27:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328186#M25540</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T21:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328187#M25541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I thank you Stewart, but I'm following up late, guess just for a little 'quality assurance' as this was something I have struggled with before too - you should credit Jake.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have fun with Python!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 21:36:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328187#M25541</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2014-04-10T21:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap10.1 Loop through a unique list to create new layers for each unique name.</title>
      <link>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328188#M25542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thought I could check both because you both contributed, didn't realize only one could receive credit haha. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good on you for pointing that out and thanks again for that last bit of help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 21:39:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcmap10-1-loop-through-a-unique-list-to-create/m-p/328188#M25542</guid>
      <dc:creator>StewartChritton</dc:creator>
      <dc:date>2014-04-10T21:39:24Z</dc:date>
    </item>
  </channel>
</rss>

