<?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 Merge Find Identical and Update Cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/merge-find-identical-and-update-cursor/m-p/53268#M4225</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As I am a newbie to python, I am trying to write the find identical feature Values into a new field in my current dataset.&amp;nbsp; I assume that I need to introduce the Update Cursor into the mix to get the desired result.&amp;nbsp; Below is my find identical script, and it is currently writing to another table.&amp;nbsp; Is there a way to consolidate it so I do not have to go through a whole other step that would include joining it &amp;amp; recalc/exporting the values back in back in?&amp;nbsp; I also have performance considerations in mind as I am working with 7+ million records, so if there is a better/faster way to do things I am very much open to it.&amp;nbsp; Here is my base code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy

from itertools import groupby
from operator import itemgetter

# Find identical records based on a text field and a numeric field.
result =arcpy.FindIdentical_management(r"C:\Users\cc1\Desktop\temp\Metro_Bus_Stops.shp", r"C:\Users\cc1\Desktop\temp\duplicate_incidents.dbf", ["City", "STREET_SER"])
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# List of all output records as IN_FID and FEAT_SEQ pair - a list of lists
out_records = []&amp;nbsp;&amp;nbsp; 
for row in arcpy.SearchCursor(result.getOutput(0), fields="IN_FID; FEAT_SEQ"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_records.append([row.IN_FID, row.FEAT_SEQ])

# Sort the output records by FEAT_SEQ values
# Example of out_records = [[3, 1], [5, 3], [1, 1], [4, 3], [2, 2]]
out_records.sort(key = itemgetter(1))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# records after sorted by FEAT_SEQ: [[3, 1], [1, 1], [2, 2], [5, 3], [4, 3]]
# records with same FEAT_SEQ value will be in the same group (i.e., identical)
identicals_iter = groupby(out_records, itemgetter(1))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# now, make a list of identical groups - each group in a list.
# example identical groups: [[3, 1], [2], [5, 4]]
# i.e., IN_FID 3, 1 are identical, and 5, 4 are identical.
identical_groups = [[item[0] for item in data] for (key, data) in identicals_iter]
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Oct 2013 17:20:16 GMT</pubDate>
    <dc:creator>ClintonCooper1</dc:creator>
    <dc:date>2013-10-22T17:20:16Z</dc:date>
    <item>
      <title>Merge Find Identical and Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/merge-find-identical-and-update-cursor/m-p/53268#M4225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As I am a newbie to python, I am trying to write the find identical feature Values into a new field in my current dataset.&amp;nbsp; I assume that I need to introduce the Update Cursor into the mix to get the desired result.&amp;nbsp; Below is my find identical script, and it is currently writing to another table.&amp;nbsp; Is there a way to consolidate it so I do not have to go through a whole other step that would include joining it &amp;amp; recalc/exporting the values back in back in?&amp;nbsp; I also have performance considerations in mind as I am working with 7+ million records, so if there is a better/faster way to do things I am very much open to it.&amp;nbsp; Here is my base code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy

from itertools import groupby
from operator import itemgetter

# Find identical records based on a text field and a numeric field.
result =arcpy.FindIdentical_management(r"C:\Users\cc1\Desktop\temp\Metro_Bus_Stops.shp", r"C:\Users\cc1\Desktop\temp\duplicate_incidents.dbf", ["City", "STREET_SER"])
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# List of all output records as IN_FID and FEAT_SEQ pair - a list of lists
out_records = []&amp;nbsp;&amp;nbsp; 
for row in arcpy.SearchCursor(result.getOutput(0), fields="IN_FID; FEAT_SEQ"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_records.append([row.IN_FID, row.FEAT_SEQ])

# Sort the output records by FEAT_SEQ values
# Example of out_records = [[3, 1], [5, 3], [1, 1], [4, 3], [2, 2]]
out_records.sort(key = itemgetter(1))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# records after sorted by FEAT_SEQ: [[3, 1], [1, 1], [2, 2], [5, 3], [4, 3]]
# records with same FEAT_SEQ value will be in the same group (i.e., identical)
identicals_iter = groupby(out_records, itemgetter(1))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# now, make a list of identical groups - each group in a list.
# example identical groups: [[3, 1], [2], [5, 4]]
# i.e., IN_FID 3, 1 are identical, and 5, 4 are identical.
identical_groups = [[item[0] for item in data] for (key, data) in identicals_iter]
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 17:20:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-find-identical-and-update-cursor/m-p/53268#M4225</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2013-10-22T17:20:16Z</dc:date>
    </item>
  </channel>
</rss>

