Question

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

  • 5 February 2018
  • 3 replies
  • 15 views

Badge

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

Userlevel 2
Badge +17

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.)

Userlevel 2
Badge +17

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.

 

Badge

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