<?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: Python: retrieving from list &amp; adding autoincrement IDs in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468872#M36594</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hayley,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Steps to complete:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Right click the field that will be update&lt;/LI&gt;&lt;LI&gt;Open up the Field Calculator; either save the attachment file and load it in the calculator or copy the Pre-Logic Script Code in the corresponding section after you check the box for Show CodeBlock in the Calculator and also Add the following to the Seciont Below the Pre-Logic Section:&lt;UL&gt;&lt;LI&gt;UniqueID( !&lt;STRONG&gt;ParkID&lt;/STRONG&gt;! )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Field Calculator:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Parser:&lt;/EM&gt; &lt;STRONG&gt;Python&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Fields:&lt;/SPAN&gt; [&lt;STRONG&gt;YOUR FIELD THAT UPDATES&lt;/STRONG&gt;]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Pre-Logic Script Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;s1 = " "&lt;/P&gt;&lt;P&gt;def UniqueID(ParkID): &lt;/P&gt;&lt;P&gt;&amp;nbsp; global s1, count&lt;/P&gt;&lt;P&gt;&amp;nbsp; y = ParkID&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = str(y)&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = s[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; if s != s1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; pad = str(count).zfill(3)&lt;/P&gt;&lt;P&gt;&amp;nbsp; z = ParkID + '_' + pad&lt;/P&gt;&lt;P&gt;&amp;nbsp; s1 = s&lt;/P&gt;&lt;P&gt;&amp;nbsp; return z&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whats going on above:&lt;/P&gt;&lt;P&gt;s1 = " " &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt; Empty String Variable that will update to hold the Value from the Field&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;def UniqueID(ParkID):&amp;nbsp; &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Defined Function the holds the meat and potatoes&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; global s1, count &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Global Variables for transfer of values in and out of function(Local)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; y = ParkID &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Variable set to hold the value of the ParkID Field&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = str(y) &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Converting the ParkID Field Value to a string Value&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = s[0] &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Taking the First index of the string value (the letter of the field value)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if s != s1: &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;A if conditional that reads the string value(letter) and compares it to the empty string from earlier&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 1 &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;count within the first conditional&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else: &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Else Conditional&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1 &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;count within the second conditional&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pad = str(count).zfill(3) &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Variable that pads zero's on to the current count (3 zero's)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; z = ParkID + '_' + pad&amp;nbsp; &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Variable that hold a concatenated string value of both the original Field Value from ParkID and added on "_" incremental count.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; s1 = s ‌&lt;STRONG style="color: #7ed529;"&gt;After the first run of the function on the first row it will set the empty variable to the field value for the conditionals, this will alow for the count to continue to add + 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; return z&lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt; Returns the value to add to table&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this doesn't work please include the error in the results. &lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;Todd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 14 Jul 2014 20:51:42 GMT</pubDate>
    <dc:creator>ToddUlery</dc:creator>
    <dc:date>2014-07-14T20:51:42Z</dc:date>
    <item>
      <title>Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468867#M36589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if you could help me write a script for Field Calculator.&lt;/P&gt;&lt;P&gt;I have a list of 2,000+ entries contained in about 40 parks. Each park has a field ParkID which is already filled out. I'd like to create a script that generates UniqueIDs based on the ParkIDs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex. ParkID = Q001&lt;/P&gt;&lt;P&gt;.:. UniqueIDs = Q001_001, Q001_002, all the way to Q001_100 or however many necessary depending on how many entries, but then beginning at 001 again when reaching a new park, i.e. R142_001, R142_002, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to first retrieve each ParkID from the list of ParkIDs and then use that list to create an autoincrement starting at 001 for each unique ParkID.&lt;/P&gt;&lt;P&gt;I'd rather do this that just do an autoincrement for each park individually.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have very little python experience and might not quite understand some details, so could you please explain in depth?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;EDIT:&lt;BR /&gt;Right now I have the following script in the Codeback of Field Calculator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rec=0 &lt;/P&gt;&lt;P&gt;plot = ""&lt;/P&gt;&lt;P&gt;def autoIncrement(park): &lt;/P&gt;&lt;P&gt; global rec &lt;/P&gt;&lt;P&gt; global plot&lt;/P&gt;&lt;P&gt; pStart = 1&amp;nbsp; &lt;/P&gt;&lt;P&gt; pInterval = 1 &lt;/P&gt;&lt;P&gt; if (rec == 0):&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; rec = pStart&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; plot = park&lt;/P&gt;&lt;P&gt;&amp;nbsp; plot = plot + "_000"+ str(rec)&lt;/P&gt;&lt;P&gt;&amp;nbsp; rec += pInterval&lt;/P&gt;&lt;P&gt; elif (rec &amp;lt; 10):&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; plot = park + "_000" + str(rec)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rec += pInterval&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt; elif (rec &amp;gt; 9 and rec &amp;lt; 100):&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; plot = park + "_00" + str(rec)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rec += pInterval&amp;nbsp; &lt;/P&gt;&lt;P&gt; elif (rec &amp;gt; 99 and rec &amp;lt; 1000):&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; plot = park + "_0" + str(rec)&lt;/P&gt;&lt;P&gt;&amp;nbsp; rec += pInterval &lt;/P&gt;&lt;P&gt; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; plot = park +&amp;nbsp; "_" + str(rec)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rec += pInterval&amp;nbsp; &lt;/P&gt;&lt;P&gt; return plot&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the following in the "FIELD_NAME" = autoIncremet(!ParkID!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This code works, but starts the unique ID at 0 and goes up into the thousands. I am trying to find a way to make it so for each new ParkID, the unique ID restarts at 001 again.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Hayley&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Hayley Small&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 15:27:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468867#M36589</guid>
      <dc:creator>HayleySmall</dc:creator>
      <dc:date>2014-07-14T15:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468868#M36590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/45402"&gt;Hayley Small&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I moved your post to the &lt;A href="https://community.esri.com/space/2145"&gt;Python&lt;/A&gt;‌ space where it should get better attention. There are many places in GeoNet which you can SEARCH for or just BROWSE&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 15:29:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468868#M36590</guid>
      <dc:creator>WesGoldstein</dc:creator>
      <dc:date>2014-07-14T15:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468869#M36591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Hayley,&lt;/P&gt;&lt;P&gt;Can I ask if the 2000 + Park data have ParkID = Q '' only? or is it a mix?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just need to know whether to account for different ParkID's in that field or if one park is only 'Q' another park is another 'P' for example?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just want to make sure I understand it fully.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Todd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 17:18:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468869#M36591</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-07-14T17:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468870#M36592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi Todd&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The parks are either "QXXX" (i.e. Q001), "XXXX" (i.e. X092), RXXX (i.e. R142), BXXX (i.e. B057), or MXXX (i.e. M321)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 17:23:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468870#M36592</guid>
      <dc:creator>HayleySmall</dc:creator>
      <dc:date>2014-07-14T17:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468871#M36593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Additionally, all Park IDs are already entered into a field "ParkID", so it would just be ParkID_001 for each new park&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 17:54:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468871#M36593</guid>
      <dc:creator>HayleySmall</dc:creator>
      <dc:date>2014-07-14T17:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468872#M36594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hayley,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Steps to complete:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Right click the field that will be update&lt;/LI&gt;&lt;LI&gt;Open up the Field Calculator; either save the attachment file and load it in the calculator or copy the Pre-Logic Script Code in the corresponding section after you check the box for Show CodeBlock in the Calculator and also Add the following to the Seciont Below the Pre-Logic Section:&lt;UL&gt;&lt;LI&gt;UniqueID( !&lt;STRONG&gt;ParkID&lt;/STRONG&gt;! )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Field Calculator:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Parser:&lt;/EM&gt; &lt;STRONG&gt;Python&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Fields:&lt;/SPAN&gt; [&lt;STRONG&gt;YOUR FIELD THAT UPDATES&lt;/STRONG&gt;]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Pre-Logic Script Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;s1 = " "&lt;/P&gt;&lt;P&gt;def UniqueID(ParkID): &lt;/P&gt;&lt;P&gt;&amp;nbsp; global s1, count&lt;/P&gt;&lt;P&gt;&amp;nbsp; y = ParkID&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = str(y)&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = s[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; if s != s1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; pad = str(count).zfill(3)&lt;/P&gt;&lt;P&gt;&amp;nbsp; z = ParkID + '_' + pad&lt;/P&gt;&lt;P&gt;&amp;nbsp; s1 = s&lt;/P&gt;&lt;P&gt;&amp;nbsp; return z&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whats going on above:&lt;/P&gt;&lt;P&gt;s1 = " " &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt; Empty String Variable that will update to hold the Value from the Field&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;def UniqueID(ParkID):&amp;nbsp; &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Defined Function the holds the meat and potatoes&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; global s1, count &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Global Variables for transfer of values in and out of function(Local)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; y = ParkID &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Variable set to hold the value of the ParkID Field&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = str(y) &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Converting the ParkID Field Value to a string Value&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; s = s[0] &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Taking the First index of the string value (the letter of the field value)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if s != s1: &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;A if conditional that reads the string value(letter) and compares it to the empty string from earlier&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 1 &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;count within the first conditional&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else: &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Else Conditional&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1 &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;count within the second conditional&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pad = str(count).zfill(3) &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Variable that pads zero's on to the current count (3 zero's)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; z = ParkID + '_' + pad&amp;nbsp; &lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt;Variable that hold a concatenated string value of both the original Field Value from ParkID and added on "_" incremental count.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; s1 = s ‌&lt;STRONG style="color: #7ed529;"&gt;After the first run of the function on the first row it will set the empty variable to the field value for the conditionals, this will alow for the count to continue to add + 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; return z&lt;SPAN style="color: #7ed529;"&gt;&lt;STRONG&gt; Returns the value to add to table&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this doesn't work please include the error in the results. &lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;Todd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 20:51:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468872#M36594</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-07-14T20:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468873#M36595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help, Todd. Unfortunately it did not work. Here are the error results:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Errors.JPG" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/2046_Errors.JPG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 21:03:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468873#M36595</guid>
      <dc:creator>HayleySmall</dc:creator>
      <dc:date>2014-07-14T21:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468874#M36596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now that I look more closely, I am actually getting a really bizarre output. It seems like some of the Unique IDs are being generated, but some of the are repeating, or restarting again at _001 at random times. Not sure why this would happen. Additionally, some of the Unique IDs are not being generated at all. I'm not sure if they just had not been gotten to before the failure occurred and the values there are leftover from my other trials, or if they are generating just strange numbers in the thousands.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are some random snippets/examples:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Ex1.JPG" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/2169_Ex1.JPG" style="height: auto;" /&gt;&lt;IMG alt="Ex2.JPG" class="jive-image image-2" src="https://community.esri.com/legacyfs/online/2170_Ex2.JPG" style="height: auto;" /&gt;&lt;IMG alt="Ex3.JPG" class="jive-image image-3" src="https://community.esri.com/legacyfs/online/2171_Ex3.JPG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex. 1 shows random numbers in the thousands in the same park as where _001 starts randomly two times.&lt;/P&gt;&lt;P&gt;Ex. 2 shows a park that goes from _001 immediately to _062&lt;/P&gt;&lt;P&gt;Ex. 3 shows a park that goes from _030 to a random numbers, and then a new park begins randomly at _033, and then a new park begins with random numbers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hayley&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jul 2014 14:24:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468874#M36596</guid>
      <dc:creator>HayleySmall</dc:creator>
      <dc:date>2014-07-15T14:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468875#M36597</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That does look a little strange. The above error is probably because of null values. In order to have to incremental numbering we needed to access the first index in the range of characters for the string (DATA VALUE). If the data is NULL it cant access that, and will say it is out of range and fail.&amp;nbsp; I would personally run a script on something like this. It allows for better access to the data. May not have the random that seems to occur. I don't know the quality of the data; i.e. what type of abnormalities to account for.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jul 2014 14:46:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468875#M36597</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-07-15T14:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468876#M36598</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Todd,&lt;/P&gt;&lt;P&gt;It actually seems like it has to do with the ObjectIDs. It seems to start over or mess up wherever the objectIDs are not perfectly ascending. For example, some data may have been collected over a large period of time, with other parks' data in between, so the object IDs are chunks at a time. IDs&amp;nbsp; 1-200 and then 2300-2450 might belong to one park,, because other parks' info was taken in between (200-2300). I'm not sure if there is a way around this- incrementing based on *not* the objectIDs, but I used the script that I wrote ^above^ and just executed it individually for each park (i.e. 40+ times), which was not ideal, but worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jul 2014 15:02:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468876#M36598</guid>
      <dc:creator>HayleySmall</dc:creator>
      <dc:date>2014-07-15T15:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468877#M36599</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hayley,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know you got it working, but I went ahead and took a pass at a script anyway.&amp;nbsp; Basically I created a dictionary that holds the "Park ID" values where the Park ID is the key, and stored the number of records that we have encountered for that park as the value.&amp;nbsp; What this allows the code to do is keep track of how many times it has encountered a particular Park ID and use that number to create the new unique ID.&amp;nbsp; It is not smart enough to updated only null records, instead it will just rebuild all the Id's, that may not be what you want in the end.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code to put in the "Pre-Logic Script Code":&lt;/P&gt;&lt;P&gt;global id_value_dict &lt;/P&gt;&lt;P&gt;id_value_dict = dict()&lt;/P&gt;&lt;P&gt;def calc_new_id(base_id_value):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; global id_value_dict&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if base_id_value in id_value_dict:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id_value_dict[base_id_value] += 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id_value_dict[base_id_value] = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; return str(base_id_value) + "_" + str(id_value_dict[base_id_value]).zfill(3)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also check out a gist of it here: &lt;A href="http://bit.ly/W9bSSC" title="http://bit.ly/W9bSSC"&gt;A quick script to create a unique ID based on the value of a different column. For example, the column value might have…&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Christopher&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jul 2014 05:22:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468877#M36599</guid>
      <dc:creator>ChristopherMoravec1</dc:creator>
      <dc:date>2014-07-16T05:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468878#M36600</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks perfect. There is really no 'one' way to do this. I was going to suggest looking at that script and alter it. I ran my script on data that was more perfect and 'yes' it was ascending nicely. It was not accounting for hiccups; just a straight run.&lt;/P&gt;&lt;P&gt;If anything I am glad you were able to get it figured out enough to get through it. Again if there are 2000 + these records on multiple tables, I might suggest writing a separate python script.&lt;/P&gt;&lt;P&gt;Would be glad to help if you need it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take care,&lt;/P&gt;&lt;P&gt;Todd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jul 2014 12:40:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468878#M36600</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-07-16T12:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468879#M36601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Hayley, I am currently writing a tool you could run. It expands on Christopher's input for using Dictionaries. Brilliant input. You may have already worked this out, but I will complete it anyway.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jul 2014 19:18:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468879#M36601</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-07-16T19:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468880#M36602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a tool you can use Hayley.&lt;/P&gt;&lt;P&gt;It has 3 parameters:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Path for table/fc&lt;/LI&gt;&lt;LI&gt;ParkID Field&lt;/LI&gt;&lt;LI&gt;UniqueID Field&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It can be batched if needed.&lt;/P&gt;&lt;P&gt;Please feel free to open it up and look at the guts of it, and don't hesitate to ask anything.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Will Need to export it; I have imported it.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course that goes for anybody else that wants to use it too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex. of prints. Should see in geoproc.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;...Unique ID S0029_010 added for S&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;Value IS NULL, Empty String, OR UNKNOWN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;Value IS NULL, Empty String, OR UNKNOWN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;Value IS NULL, Empty String, OR UNKNOWN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;Value IS NULL, Empty String, OR UNKNOWN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt; 0034 ...Value IS GOOD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;{'Q': 10, ' ': 1, 'S': 10, 'R': 1}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt; 0034&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;...Unique ID&amp;nbsp; 0034_001 added for&lt;/SPAN&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;T0035 ...Value IS GOOD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;{'Q': 10, ' ': 1, 'S': 10, 'R': 1, 'T': 1}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4fcddc;"&gt;T0035 T&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;...Unique ID T0035_001 added for T&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;I am determined to make this work. So let me know if i have not accounted for something and share the error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;Todd&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jul 2014 21:17:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468880#M36602</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-07-16T21:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python: retrieving from list &amp; adding autoincrement IDs</title>
      <link>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468881#M36603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for this code.&amp;nbsp; I was looking for an auto-increment tool that would work on a varying base id field.&amp;nbsp; This worked perfect.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 19:23:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-retrieving-from-list-adding-autoincrement/m-p/468881#M36603</guid>
      <dc:creator>TomGoeke</dc:creator>
      <dc:date>2014-07-17T19:23:49Z</dc:date>
    </item>
  </channel>
</rss>

