Skip to main content

I have a list which contains these values:

nl restservicesMonumenten_raadplegenMapServer   

nl restservicesBR_GroenstructuurplankaartMapServer  

nl restservicesBR_GroenstructuurplankaartMapServer   

nl restservicesBijzondere_BomenFeatureServer   

nl restservicesBR_BAGFeatureServer  

nl restservicesBR_BAGFeatureServer   

nl restservicesVERG_TOEZOPLOSFeatureServer   

nl restservicesVERG_TOEZOPLOSFeatureServer   

nl restservicesVERG_TOEZOPLOSFeatureServer   

nl restservicesVERG_TOEZOPLOSFeatureServer   

nl restservicesPROJ_Mut_editFeatureServer   

nl restservicesPROJ_Mut_editFeatureServer   

nl restservicesPROJ_Mut_editFeatureServer   

nl restservicesPROJ_Mut_editFeatureServer   

nl restservicesPROJ_Mut_editFeatureServer

 

In want to clean up this list by removing the duplicate strings. However, I want to keep the number of times each string occures. Finally, I want to get this list which stores after each string the number of occurence as shown in my first list:

 

nl restservicesMonumenten_raadplegenMapServer  (1)

nl restservicesBR_GroenstructuurplankaartMapServer   (2)

nl restservicesBijzondere_BomenFeatureServer   (1)

nl restservicesBR_BAGFeatureServer   (2)

nl restservicesVERG_TOEZOPLOSFeatureServer (4)

nl restservicesPROJ_Mut_editFeatureServer   (5)

 

Any ideas? I have tried something with an AttributeSplitter folllowed by a ListHistogrammer which leads to two lists. However, I was not able to combine them so far.

You could explode the list after the ListHistogrammer, create the new text from the name and the count then rebuild the list

Capture


Working with lists generally is one area where doing something in python can be more straightforward than using FME. This would take a list called list{} and replace it with a list of the same name but removing the duplicates and adding the counts

import fme
import fmeobjects
from collections import Counter
 
def processFeature(feature):
    #get list item
    mylist = feature.getAttribute('list{}')
    #set count
    count = 0
    #remove original list now stored in mylist
    feature.removeAttribute('list{}')
    #use Counter to count occurrences of value in list and iterate through 
    for k,v in Counter(mylist).items():
        count +=1
        #set newlist attribute
        feature.setAttribute("list{"+str(count)+"}",k + " ("+str(v)+")")

 Capture


You could explode the list after the ListHistogrammer, create the new text from the name and the count then rebuild the list

Capture

Thanks, works perfect!


Reply