<?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: Find duplicates, update only one record in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749474#M57905</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I added comments to the code above. I would get it into a python IDE and step through it with a debugger. Doing this when I am taking on something new speeds up my learning... it takes away the "back box" effect.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Aug 2020 22:16:30 GMT</pubDate>
    <dc:creator>forestknutsen1</dc:creator>
    <dc:date>2020-08-17T22:16:30Z</dc:date>
    <item>
      <title>Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749466#M57897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;I would like to only populate one of the&amp;nbsp; duplicate record but with number of duplicates like below.&lt;/P&gt;&lt;P&gt;How can do this or what is the best way to achieve this with python?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;well_id      Dup

D36528   3

D36528

D36528

D36532   2

D36532

D36521

D36522

D36525   2

D36525&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:50:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749466#M57897</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-12-12T07:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749467#M57898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use dictionaries to count the number of repeating ids. Maybe something like this...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ids = [&lt;SPAN style="color: #a5c261;"&gt;'D36528'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36528'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36528'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36532'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36532'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36521'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36522'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36525'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;       &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'D36525'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;]

ids_dict = {}

uids = &lt;SPAN style="color: #8888c6;"&gt;list&lt;/SPAN&gt;(&lt;SPAN style="color: #8888c6;"&gt;set&lt;/SPAN&gt;(ids))

&lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;uid &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;uids:
    ids_dict[uid] = []

&lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;id &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;ids:
    ids_dict[id] = ids_dict[id] + [id]

&lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;k&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;v &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;ids_dict.items():
    &lt;SPAN style="color: #cc7832;"&gt;print &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;'{k}, {n}'&lt;/SPAN&gt;.format(&lt;SPAN style="color: #aa4926;"&gt;k&lt;/SPAN&gt;=k&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;n&lt;/SPAN&gt;=&lt;SPAN style="color: #8888c6;"&gt;len&lt;/SPAN&gt;(v))

&lt;/PRE&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;D36532, 2&lt;BR /&gt;D36528, 3&lt;BR /&gt;D36521, 1&lt;BR /&gt;D36522, 1&lt;BR /&gt;D36525, 2&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:50:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749467#M57898</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2021-12-12T07:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749468#M57899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or for something completely different... out to *.dbf or *.csv&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; numpy &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; np
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; NumPyArrayToTable
&lt;SPAN class="comment token"&gt;#&lt;/SPAN&gt;
ids &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'D36528'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'D36528'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'D36528'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'D36532'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'D36532'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
       &lt;SPAN class="string token"&gt;'D36521'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'D36522'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'D36525'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'D36525'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# ---- numpy magic&lt;/SPAN&gt;
u&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; c &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;unique&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ids&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; return_counts&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
dt &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dtype&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Class"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"&amp;lt;U7"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Count"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"i4"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
uc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;asarray&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;list&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;zip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;u&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; c&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; dtype&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;dt&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# ---- output to dbf and csv&lt;/SPAN&gt;
NumPyArrayToTable&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;uc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"c:/temp/out.dbf"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;savetxt&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"c:/temp/out.csv"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; uniq_counts&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fmt&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%7s, %3s"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; 
           comments&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; header&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Class, Counts"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The csv as an example&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Class, Counts
 D36521,   1
 D36522,   1
 D36525,   2
 D36528,   3
 D36532,   2&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can add the *.csv or *.dbf to arcmap or Pro, or join to an existing table&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:50:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749468#M57899</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-12T07:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749469#M57900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do reading the valuse from a dictionary use dict for with arcpy.da.UpdateCursor?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Aug 2020 17:34:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749469#M57900</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2020-08-14T17:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749470#M57901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure I understand your question. Maybe it would be helpful if we had a little more info...&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;what format is your original data is in? e.g. csv, feature class in a fgdb, database... etc.&lt;/LI&gt;&lt;LI&gt;what is your target format? e.g.&amp;nbsp;&lt;SPAN&gt;feature class in a fgdb&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;can you give us an overview of what you are trying to do?&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would use an update cursor to write the info from the dictionary back to a feature class in a fgdb for sure.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Aug 2020 01:05:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749470#M57901</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2020-08-15T01:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749471#M57902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data is in a&amp;nbsp; feature class in a fgdb.&lt;/P&gt;&lt;P&gt;I want to be able to see how many times an attribute is duplicated in a the field well_Id but I don't need all of them to have a number in the Dup filed but if that is the only way then that is ok. How do I take k &amp;amp; n and write to the feature class thought update cursor?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2020 14:46:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749471#M57902</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2020-08-17T14:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749472#M57903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use a search cursor to read in the ids and then an update cursor the write the count out the feature class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

fc_path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\my_temp\junk3\geo\fgdb.gdb\wells'&lt;/SPAN&gt;

ids &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_path&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ID'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        ids&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# make empty dict&lt;/SPAN&gt;
ids_dict &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# get a list of unique ids, e.g. remove duplicates, set does this &lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# then just convert it back to a list&lt;/SPAN&gt;
uids &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; list&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;set&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ids&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# for each uid make a dict item with the key the uid and an empty list as the value &lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; uid &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; uids&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    ids_dict&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;uid&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# this is what sets you up for counting. it finds the matching well id keys &lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# and adds the key to the list value so you get in the dict {'w1': [w1, w1, w1]}&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# then all you need to do count the length of the value list.&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; id &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; ids&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    ids_dict&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;id&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; ids_dict&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;id&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;id&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_path&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'ID'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'DUP'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; k&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; v &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; ids_dict&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;items&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
            &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; k &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; v &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;not&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
                row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;v&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
                ids_dict&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;k&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; None
                cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;updateRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:50:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749472#M57903</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2021-12-12T07:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749473#M57904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank for sharing.&lt;/P&gt;&lt;P&gt;Can you explain what lines 11-19 are doing please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2020 20:24:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749473#M57904</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2020-08-17T20:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749474#M57905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I added comments to the code above. I would get it into a python IDE and step through it with a debugger. Doing this when I am taking on something new speeds up my learning... it takes away the "back box" effect.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2020 22:16:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749474#M57905</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2020-08-17T22:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749475#M57906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In terms of semantics, you are calling the field you want to populate "Dup", but you are putting the total count of records in that field unless there is only 1 record.&amp;nbsp; As Dan and Forest have already implied, it is probably better to go with a field name like "Count" and then put the total count of records for all records.&amp;nbsp; If you want to know which records have a duplicate, triplicate, etc...; you simply query on Count being greater than 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Along the lines of Forest's answer, but using slightly more compact code without having to create two cursors:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; UpdateCursor
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; collections &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; Counter

fc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to feature class&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"well_id"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Dup"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    cnt &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Counter&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    cur&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;reset&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        cur&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;updateRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; cnt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pop&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    

 &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:50:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749475#M57906</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T07:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749476#M57907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like your's best Joshua, nice and clean &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Aug 2020 21:18:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749476#M57907</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2020-08-18T21:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749477#M57908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The Counter object was purpose built for situations like this.&amp;nbsp; Granted, it is fairly easy to implement with a dict or defaultdict, but there are some handy performance and syntax optimizations using the custom object.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Aug 2020 21:37:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749477#M57908</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-08-18T21:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Find duplicates, update only one record</title>
      <link>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749478#M57909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see that now -- I googled the Counter object right after reading your post. I am going to add it to my python toolbox.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Aug 2020 23:06:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-duplicates-update-only-one-record/m-p/749478#M57909</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2020-08-18T23:06:33Z</dc:date>
    </item>
  </channel>
</rss>

