1

I tried using the same codeblock as Removing duplicates from field using ArcPy with ArcMap, but it is just copying the contents and not removing duplicates. I think my data is formatted the same.

What am I missing?

Codeblock

def delDups(n):
  return ', '.join(set(n.split(', ')))

Expression

delDups( !Names3! )

enter image description here

1
  • 2
    You split should say " ," ie space, comma.
    – FelixIP
    Mar 1 '19 at 23:00
4

I think this should work with your data:

', '.join(set(filter(None, [b.strip() for b in n.split(',')])))

Strip to remove whitespaces before and after string, filter to remove empty strings, set to remove duplicates and then join back to a comma separated string:

a = ",East pass ,Iris Bloom Cir ,East pass"
', '.join(set(filter(None, [b.strip() for b in a.split(',')])))
'Iris Bloom Cir, East pass'
0

I wasn't able to get the two suggestions to work, but I had success when I reformatted the data with "&" enter image description here

and used:

def delDups(n):
 return ' & '.join(set(n.split(' & ')))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.