Skip to main content
Solved

Get the number of different values in a list

  • February 5, 2015
  • 2 replies
  • 90 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)
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, 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
Influencer
  • 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

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings