<?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: Recursive Python Function in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240043#M18687</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well, like I said, I was kind of nitpicking. A true recursive function is one that calls itself, not one that is called multiple times in a loop. A classic example is finding factorials:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&lt;SPAN style="color:#000000;"&gt;def factorial&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;if &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number &amp;lt;= &lt;/SPAN&gt;&lt;SPAN style="color:#990000;"&gt;1&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;return &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#990000;"&gt;1&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;else&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;return &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number * factorial&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number - &lt;/SPAN&gt;&lt;SPAN style="color:#990000;"&gt;1 &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;)&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;You could do the same thing in a loop, which is usually easier to understand, but a recursive call is much more efficient - runs faster, less overhead, etc. - in many cases.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 12:04:51 GMT</pubDate>
    <dc:creator>Zeke</dc:creator>
    <dc:date>2021-12-11T12:04:51Z</dc:date>
    <item>
      <title>Recursive Python Function</title>
      <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240037#M18681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So I have no clue how to do this but I'm 99% positive it's possible...I think.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to execute a function against every single feature in a feature class, but in a sequential and recursive manner. So let's say I'm creating a network value for each feature. The network value for each feature depends on the value of other items in the network. So every time the network value for a feature is calculated, all previously calculated values must be recalculated in order to account for the value of the newly calculated feature's network value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, let's say I have a feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FeatureClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[TABLE="class: cms_table_cms_table_grid"]IDShapeNameNetwork Value1PointFeature1&amp;lt;Null&amp;gt;2PointFeature2&lt;/SPAN&gt;&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;3PointFeature3&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;4PointFeature4&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;5PointFeature5&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;&lt;BR /&gt;[/TABLE]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I want to calculate the value for Feature1.&lt;BR /&gt;[TABLE="class: cms_table_cms_table_grid"]IDShapeNameNetwork Value1PointFeature11002PointFeature2&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;3PointFeature3&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;4PointFeature4&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;5PointFeature5&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;&lt;BR /&gt;[/TABLE]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:#3E3E3E;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;Then I want to calculate the value for Feature2.&lt;BR /&gt;[TABLE="class: cms_table_cms_table_grid"]IDShapeNameNetwork Value1PointFeature11002PointFeature2&lt;DIV align="center"&gt;933PointFeature3&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;4PointFeature4&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;5PointFeature5&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;&lt;BR /&gt;[/TABLE]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But now there are multiple items in the network which means that now Feature1's network value is possibly incorrect, so Feature1 has to be recalculated.. &lt;BR /&gt;[TABLE="class: cms_table_cms_table_grid"]IDShapeNameNetwork Value1PointFeature1982PointFeature2&lt;DIV align="center"&gt;933PointFeature3&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;4PointFeature4&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;5PointFeature5&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;&lt;BR /&gt;[/TABLE]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now calculate the network value for Feature3, then recalculate Feature2, then recalculate Feature1&lt;BR /&gt;[TABLE="class: cms_table_cms_table_grid"]IDShapeNameNetwork Value1PointFeature1922PointFeature2&lt;DIV align="center"&gt;883PointFeature3&lt;DIV align="center"&gt;764PointFeature4&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;5PointFeature5&lt;DIV align="center"&gt;&amp;lt;Null&amp;gt;&lt;BR /&gt;[/TABLE]&lt;BR /&gt;&lt;BR /&gt;So on and so forth until I've calculated a network value for Feature5 and recalculated the values for features 1-4&lt;BR /&gt;&lt;BR /&gt;Then stop the iteration.&lt;BR /&gt;&lt;BR /&gt;any help or info is appreciated...&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 18:51:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240037#M18681</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2013-04-18T18:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive Python Function</title>
      <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240038#M18682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Note sure about your specific case or the exact logic you are employing in your workflow, but the general method of recursion relies on using a while loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a basic hypothetical example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myFC = r"C:\temp\test.gdb\test"
featuresProcessedCount = 0
featureCount = int(arcpy.GetCount_management(myFC).getOutput(0))
while featuresProcessedCount &amp;lt; featureCount:
&amp;nbsp;&amp;nbsp; do something
&amp;nbsp;&amp;nbsp; featuresProcessedCount = featuresProcessedCount + 1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:04:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240038#M18682</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T12:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive Python Function</title>
      <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240039#M18683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply Chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a great start. I'll give it a go today and&amp;nbsp; see how far I get...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Much appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Apr 2013 13:11:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240039#M18683</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2013-04-19T13:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive Python Function</title>
      <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240040#M18684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Note sure about your specific case or the exact logic you are employing in your workflow, but the general method of recursion relies on using a while loop.&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I apologize if this seems pedantic, but a recursive function is one that calls itself, not one that loops per se. You can often (always?) accomplish the same thing either way, but one or the other may be more efficient depending on what you're doing. Loops are definitely easier to understand though.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Apr 2013 15:17:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240040#M18684</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2013-04-19T15:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive Python Function</title>
      <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240041#M18685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I apologize if this seems pedantic, but a recursive function is one that calls itself, not one that loops per se. You can often (always?) accomplish the same thing either way, but one or the other may be more efficient depending on what you're doing. Loops are definitely easier to understand though.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hey Gregg,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;No worries, I wasn't sure if I was using the right term or not. Technically though, I think this would be recursive because the function, let's say its "CalculateField_management" for this purpose, does need to call itself again after every complete iteration.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So once it calculates the field for record 2, it needs to go back and caluclate the field for record 1 again. Once it calculates the field for record 3, it needs to go back and calculate the field for records 1 and 2 again...then go on to calculate the field for record 4 and again go back and calculate the field for records 1, 2 and 3 again...over and over and over again until it's calcuated the field for the very last feature and then gone back and calculated the field for every feature before the last feature. It makes my brain hurt just thinking about it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sorry I cant reveal more about the function, but it's proprietary. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are 957 features in the feature class, so I'm trying to avoid having to code 956 loops, if that makes sense.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I think this is recursive based on my understanding of recusion...perhaps not, it wouldnt be the first time I was wrong.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Apr 2013 15:42:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240041#M18685</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2013-04-19T15:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive Python Function</title>
      <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240042#M18686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;a recursive function is one that calls itself, not one that loops per se&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I often find that it's easier to implement "recursion" in a loop of some sort though. Maybe what I think of as "recursion" isn't technically recursion... I'm not a formally trained programmer by any means, so appologies if what I say is utter nonsense!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That said - Here's a practical ArcGIS/Python example of something I would consider recursion. This code assigns a unique identifier (a "cluster ID" if you will) to features that within a given distance of each other (basically a "select by location" that keeps executing as long as the selected set grows. Once there are no more features to select, then it tries to select another seed feature (that hasn't already been assigned a CLUSTER_ID value) in which to "grow" the next cluster from. It uses while loops and not function calls, although I supose it could be re-written to do that. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys, string, os, arcpy
inLayer = arcpy.GetParameterAsText(0) #input layer
clusterIdField = arcpy.GetParameterAsText(1) #the name of the 'CLUSTER_ID' field that will be added to inLayer
selectionMethod = arcpy.GetParameterAsText(2) #the selectbylocation method (such as WITHIN_A_DISTANCE or INTERSECT)
distThreshold = arcpy.GetParameterAsText(3) #A distance threashold if using the WITHIN_A_DISTANCE selection method 
selectionBuffer = arcpy.GetParameterAsText(4) #A max number of features to be selected set at once... performace gets slow if selection gets too big 
if selectionBuffer in ("","#",None):
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionBuffer = 500
if int(selectionBuffer) &amp;lt; 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionBuffer = 500
fieldList = arcpy.ListFields(inLayer, clusterIdField)
if fieldList == []:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(inLayer, clusterIdField, "LONG")
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fieldList[0].type not in ["SmallInteger","Integer","Double","Float"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("ERROR: Existing " + str(clusterIdField) + " field type must be a numeric type (not a type of " + str(fieldList[0].type) + "! Exiting script..."); sys.exit(1)
oidFieldName = arcpy.Describe(inLayer).oidFieldName
arcpy.AddMessage("Cataloging " + str(oidFieldName) + " values...")
oidDict = {}
for r in arcpy.da.SearchCursor(inLayer, ["OID@"]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; oidDict[r[0]] = -1
featureCount = len(oidDict)
if featureCount == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("ERROR: Could not find any features to identify! Exiting script...");sys.exit(1)
arcpy.AddMessage("Looking for clusters...")&amp;nbsp;&amp;nbsp; 
identifiedFeatures = 0
clusterId = 0
arcpy.MakeFeatureLayer_management(inLayer, "fl1", "") #Test to see if this helps clear the memory leak
arcpy.SetProgressor("step", "Progress", 0, 100, 1)
pctDone = 0
while identifiedFeatures &amp;lt; featureCount:
&amp;nbsp;&amp;nbsp;&amp;nbsp; clusterId =&amp;nbsp; clusterId + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nextOidSeedValue = (key for key,value in oidDict.items() if value == -1).next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("fl1", "NEW_SELECTION", oidFieldName + " = " + str(nextOidSeedValue))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; globalPreSelectionOidSet = set()
&amp;nbsp;&amp;nbsp;&amp;nbsp; globalPostSelectionOidSet = set([nextOidSeedValue]) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; loopCount = 0 #for fun
&amp;nbsp;&amp;nbsp;&amp;nbsp; bufferReductionCount = 0 #for fun
&amp;nbsp;&amp;nbsp;&amp;nbsp; while len(globalPostSelectionOidSet) &amp;gt; len(globalPreSelectionOidSet):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; loopCount = loopCount + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; preSelectionOidSet = set([r[0] for r in arcpy.da.SearchCursor("fl1", ["OID@"])])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; globalPreSelectionOidSet = globalPreSelectionOidSet.union(preSelectionOidSet)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("fl1", selectionMethod, "fl1", distThreshold, "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; postSelectionOidSet = set([r[0] for r in arcpy.da.SearchCursor("fl1", ["OID@"])])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; globalPostSelectionOidSet = globalPostSelectionOidSet.union(postSelectionOidSet)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(postSelectionOidSet) &amp;gt; int(selectionBuffer):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; recentSelectionOidList = list(globalPostSelectionOidSet.difference(globalPreSelectionOidSet))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; recentSelectionOidList.sort()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(recentSelectionOidList) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bufferReductionCount = bufferReductionCount + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("fl1", "NEW_SELECTION", oidFieldName + " in (" + ",".join(str(i) for i in recentSelectionOidList) + ")")
&amp;nbsp;&amp;nbsp;&amp;nbsp; for oidValue in globalPostSelectionOidSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; identifiedFeatures = identifiedFeatures + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oidDict[oidValue] = clusterId
&amp;nbsp;&amp;nbsp;&amp;nbsp; pctDoneUpdate = int(identifiedFeatures/float(featureCount) * 100)
&amp;nbsp;&amp;nbsp;&amp;nbsp; pctDoneDiff = pctDoneUpdate - pctDone
&amp;nbsp;&amp;nbsp;&amp;nbsp; if pctDoneDiff &amp;gt;= 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(0,pctDoneDiff):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetProgressorPosition()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pctDone = pctDoneUpdate
arcpy.AddMessage("Updating attribute table...")
updateRows = arcpy.da.UpdateCursor(inLayer, ["OID@",clusterIdField])
for updateRow in updateRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow[1] = oidDict[updateRow[0]]
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)
del updateRow, updateRows
arcpy.AddMessage("Identified " + str(clusterId) + " cluster(s) for " + str(identifiedFeatures) + " features")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:04:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240042#M18686</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T12:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive Python Function</title>
      <link>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240043#M18687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well, like I said, I was kind of nitpicking. A true recursive function is one that calls itself, not one that is called multiple times in a loop. A classic example is finding factorials:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&lt;SPAN style="color:#000000;"&gt;def factorial&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;if &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number &amp;lt;= &lt;/SPAN&gt;&lt;SPAN style="color:#990000;"&gt;1&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;return &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#990000;"&gt;1&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;else&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#7f0055;"&gt;&lt;STRONG&gt;return &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number * factorial&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;number - &lt;/SPAN&gt;&lt;SPAN style="color:#990000;"&gt;1 &lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;)&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;You could do the same thing in a loop, which is usually easier to understand, but a recursive call is much more efficient - runs faster, less overhead, etc. - in many cases.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:04:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/recursive-python-function/m-p/240043#M18687</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2021-12-11T12:04:51Z</dc:date>
    </item>
  </channel>
</rss>

