I am using the concatenate function in the dissolve tool but need the output results to be distinct. Where the concatenate would yield A, B, B, C, D I would want the result to remove the duplicated B. A, B, C. If you run this gp tool via python is there a way to add a distinct function to the code?
Solved! Go to Solution.
here is the solution:
var field = $feature.CONCATENATE_Acquisition_Source
var spfield = Split(field,"; ")
var dist = distinct(spfield)
return Concatenate(dist, "; ")
Another option would be a field calculator after the gp tool that remove duplicates from the text string.
using as many python functions as I can 😉
a = 'A, B, B, C, D'
z0 = ", ".join(sorted(list(set(a.replace(" ", ""))))[1:])
z0
'A, B, C, D'
you will have to replace `a` with !YourFieldName! with the ! marks
If the string is formatted differently you can modify to suit
I am not sure how to apply this code. Through notebook or field calculator? Would this apply to each row in a table?
When I run this through notebook here is what it looks like:
Do I need to define the dataset prior to the field?
It is a field calculator expression and when I mean replace `a` in the expression, then I mean substitute it with your field name
I have been trying that and I cannot get the format to work. Not sure if I have this formatted correct but when I make a = field I get an invalid syntax.
expression
func(!CONCAT....!) # enter your field name... too long for me to type
code block
def func(a):
return ", ".join(sorted(list(set(a.replace(" ", ""))))[1:])
this expression ran but it did not produce the desired result. Instead of cleaning out it created a bunch of new coma delimited data.
here is the solution:
var field = $feature.CONCATENATE_Acquisition_Source
var spfield = Split(field,"; ")
var dist = distinct(spfield)
return Concatenate(dist, "; ")