Skip to main content
Solved

Get the number of different values in a list

  • February 5, 2015
  • 2 replies
  • 120 views

Forum|alt.badge.img
Hi!

 

 

I have a list attribute such this one:

 

 

['a', 'b', 'c', 'a', 'b']

 

 

I would like to have the number of different values present in that list.

 

 

In python I would do: 
 list=['a', 'b', 'c', 'a', 'b'] len(set(list)) >>> 3
 Is it possible to get that count with some fme transformer?

 

 

Best answer by gio

Just use ListDuplicateRemover and than ListElementCounter. (if it is a valid list to fme that is)
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • Best Answer
  • February 5, 2015
Just use ListDuplicateRemover and than ListElementCounter. (if it is a valid list to fme that is)

takashi
Celebrity
  • February 6, 2015
Hi,

 

 

Alternatively, if you don't want to modify the original list, use the ListHistogrammer instead and then count the number of elements of the resulting "_histogram" list with the ListElementCounter.

 

 

I think your Python solution is elegant and efficient.

 

-----

 

# Script Example for PythonCaller

 

def countUniqueElements(feature):

 

    feature.setAttribute('_count', len(set(feature.getAttribute('_list{}'))))

 

-----

 

 

Takashi