Select to view content in your preferred language

Duplicate Values

1556
5
Jump to solution
09-19-2014 10:08 AM
RickWarner
Occasional Contributor

I have a table that has one field with duplicate values. Is there any code that will label the duplicates 0, 1, 2, 3, 4 ..., rather than 0 and 1 as the following code does which I've found on ESRI's web site.

Python parser, and use  then use the following codebook.

uniqueList = []

def isDuplicate(inValue):

  if inValue in uniqueList:

    return 1

  else:

    uniqueList.append(inValue)

    return 0

isDuplicate(!PCN!)

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
BrianCarson2
Esri Contributor

uniqueList={}

def isDuplicate(inValue):

    global uniqueList

    if inValue in uniqueList.keys():

        uniqueList[inValue] += 1

        return uniqueList[inValue]

    else:

        uniqueList[inValue] = 0

        return uniqueList[inValue]

Using the Python Parser, insert the following into the code block.

This will perform the same operation as the above, but will increment the duplicate records as 0, 1, 2, 3 ... and then revert to 0 when it hits the next unique value.

At the end you would then use the isDuplicate(!<Your Field Name>!)

View solution in original post

5 Replies
forestknutsen1
MVP Regular Contributor

I am not sure I understand. You are saying that you have a field that has values like 1,2,2,3,4,4,5 etc. and you want 1,2,3,4,5,6 what is the value of this. Why not just use the OID if you need a UID (unique identifier). If this will not work-  what you want can be done with python using an UpdateCursor: here is info on it.

ArcGIS Help 10.1

then just update the row with a count variable. and increment it each time though the loop. count += 1 i.e. count = count + 1

BrianCarson2
Esri Contributor

uniqueList={}

def isDuplicate(inValue):

    global uniqueList

    if inValue in uniqueList.keys():

        uniqueList[inValue] += 1

        return uniqueList[inValue]

    else:

        uniqueList[inValue] = 0

        return uniqueList[inValue]

Using the Python Parser, insert the following into the code block.

This will perform the same operation as the above, but will increment the duplicate records as 0, 1, 2, 3 ... and then revert to 0 when it hits the next unique value.

At the end you would then use the isDuplicate(!<Your Field Name>!)

RickWarner
Occasional Contributor

Brian, thank you so much, it worked perfectly.

DanPatterson_Retired
MVP Emeritus

this thread still remains open, if a solution was provided please select the correct answer to finalize the discussion

0 Kudos
RickWarner
Occasional Contributor

This best answer which worked perfectly was by B Carslon.

Thanks so much…

0 Kudos