Skip to main content
Question

Ho do I find one or multiple ranges in list values?

  • February 5, 2018
  • 3 replies
  • 143 views

Forum|alt.badge.img

I am trying to find one or multiple ranges of values within a list in the most efficient way.

My list-attribute looks like this: (1, 2, 3, 5, 6, 7, 9, 12,13,14,15,16).

I would like to end up with the following result: (1-3, 5-7, 9,12-16).

Is there an efficient way to do this without coding? Maybe using the variable setter?

Since I am using only positive integers, my current way consists of adding 1 and substracting 1 to each value, then using mergers to find out, if the corresponding next value upwards or downwards exists, and then dividing my values into classes:

- values that were not assigned the next upper or lower value --> keep as single value

- values that were assigned upper only --> keep as lower value

- values that were assigned lower only --> keep as upper value

- values that have both --> ditch.

3 replies

takashi
Influencer
  • February 5, 2018

Hi @jakobrehbach, if an element whose value - 1 is not equal to the previous element value, it would be the start of a new range. My idea is to add the same ID to every element while it's not a new starting element, then group the elements by the ID. The idea is simple, but the implementation could be a little complicated. e.g. (Assume "_list{}" stores the sequence of positive integer values.)


takashi
Influencer
  • February 5, 2018
takashi wrote:

Hi @jakobrehbach, if an element whose value - 1 is not equal to the previous element value, it would be the start of a new range. My idea is to add the same ID to every element while it's not a new starting element, then group the elements by the ID. The idea is simple, but the implementation could be a little complicated. e.g. (Assume "_list{}" stores the sequence of positive integer values.)

Another thought. This may be close to your idea.

 


Forum|alt.badge.img
  • Author
  • February 5, 2018

Thanks! For some reason I hadn't thought about the adjacent features option in the AttributeCreator. This has cleaned up my workspace and it runs more quickly now.


Reply


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