<?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: Calculate Field with Python in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040118#M38916</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Thank you for your reply.&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AAAAA.JPG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9270i94438FE43E769F0C/image-size/large?v=v2&amp;amp;px=999" role="button" title="AAAAA.JPG" alt="AAAAA.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 12:00:30 GMT</pubDate>
    <dc:creator>KalSsin</dc:creator>
    <dc:date>2021-03-24T12:00:30Z</dc:date>
    <item>
      <title>Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040109#M38913</link>
      <description>&lt;DIV&gt;uniqueList = []&lt;/DIV&gt;&lt;DIV&gt;def isDuplicate(inValue):&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; if inValue in uniqueList:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; return 1&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; else:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; uniqueList.append(inValue)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; return 0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi~~~&lt;SPAN&gt;Please refer to the illustration.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Above coding to output 0 1.&lt;BR /&gt;I'd like to output 1 1.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="qqqq.JPG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9266iDB6367E4209CC4F2/image-size/large?v=v2&amp;amp;px=999" role="button" title="qqqq.JPG" alt="qqqq.JPG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 11:32:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040109#M38913</guid>
      <dc:creator>KalSsin</dc:creator>
      <dc:date>2021-03-24T11:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040111#M38914</link>
      <description>&lt;P&gt;Which field are you calculating on? Also unsure of the logic of that code compared to your expected output - doesn't make sense to me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, as the code is executed on a per-row basis with the function, unique_list would have to be set to a global.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;uniqueList = []
def isDuplicate(inValue):
  global uniqueList
  if inValue in uniqueList:
    return 1
  else:
    uniqueList.append(inValue)
    return 0&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 Mar 2021 11:35:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040111#M38914</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-03-24T11:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040118#M38916</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for your reply.&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AAAAA.JPG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9270i94438FE43E769F0C/image-size/large?v=v2&amp;amp;px=999" role="button" title="AAAAA.JPG" alt="AAAAA.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:00:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040118#M38916</guid>
      <dc:creator>KalSsin</dc:creator>
      <dc:date>2021-03-24T12:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040119#M38917</link>
      <description>&lt;P&gt;Are you saying the top picture is what you want - that makes sense to me - rather than the bottom picture?&lt;/P&gt;&lt;P&gt;looking at the code, I don't see how you got those results in the bottom picture either.&amp;nbsp; Did you try the code I suggested?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:08:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040119#M38917</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-03-24T12:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040122#M38918</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I used your code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The picture below is the printout I want. I used your code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd like to express all duplicate names by 1.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:13:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040122#M38918</guid>
      <dc:creator>KalSsin</dc:creator>
      <dc:date>2021-03-24T12:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040124#M38919</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="XX.JPG" style="width: 756px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9271i374DA8A259237C4A/image-size/large?v=v2&amp;amp;px=999" role="button" title="XX.JPG" alt="XX.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:15:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040124#M38919</guid>
      <dc:creator>KalSsin</dc:creator>
      <dc:date>2021-03-24T12:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040135#M38920</link>
      <description>&lt;P&gt;I'd probably run a searchCursor to generate a list of unique values, then run the field calculator using that list of pregenerated unique values.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:32:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040135#M38920</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-03-24T12:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040140#M38921</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for your reply.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:44:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040140#M38921</guid>
      <dc:creator>KalSsin</dc:creator>
      <dc:date>2021-03-24T12:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field with Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040153#M38923</link>
      <description>&lt;P&gt;It may be easier to do this with a script rather than the Field Calculator.&amp;nbsp; Ex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

table = r"C:\TEMP\PYTHON\Test.gdb\XY"

nameDict = {}

with arcpy.da.SearchCursor(table, ["NAME"]) as cursor:
     for row in cursor:
         if row[0] not in nameDict.keys():
             nameDict[row[0]] = 0
         else:
             nameDict[row[0]] = 1
del cursor

with arcpy.da.UpdateCursor(table, ["NAME", "Field"]) as cursor:
     for row in cursor:
         row[1] = nameDict[row[0]]
         cursor.updateRow(row)
del cursor&lt;/LI-CODE&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1616590859062.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9278i2235BE84EDF1A257/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1616590859062.png" alt="JakeSkinner_0-1616590859062.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 13:01:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-python/m-p/1040153#M38923</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-03-24T13:01:10Z</dc:date>
    </item>
  </channel>
</rss>

