How do I retrieve the lowers and uppers bounds in a
discontinuous list of values (alphanumeric)?
Example of list: {5, 6, 7, 8, 10a, 11, 15, 16x, 17, 18,
19, 20, 25}
The extraction I'm looking for would be: 5-8, 10a-11, 15-20, 25
Thank you
How do I retrieve the lowers and uppers bounds in a
discontinuous list of values (alphanumeric)?
Example of list: {5, 6, 7, 8, 10a, 11, 15, 16x, 17, 18,
19, 20, 25}
The extraction I'm looking for would be: 5-8, 10a-11, 15-20, 25
Thank you
I'm sure this can be done using transformers, but I suspect it'll be rather convoluted. Here's a possible solution using a PythonCaller:
import fmeobjects
from itertools import groupby
from operator import itemgetter
def str2int(s):
    return int(''.join(
def split_list_at_bounds(feature):
    data = feature.getAttribute('values')
    if data:
        data = vx.strip() for x in data.replace('{', '').replace('}', '').split(',')]
        bounds = p]
        for k, g in groupby(enumerate(data), lambda (i,x):i-str2int(x)):
            bounds.append(map(itemgetter(1), g))
        for n, boundary in enumerate(bounds):
            if len(boundary) == 1:
                s = boundaryÂ0]
            else:
                s = '-'.join(Âboundary 0], boundaryu-1]])
            feature.setAttribute('boundary{%s}' % n, s)
Assuming the input attribute values = "{5, 6, 7, 8, 10a, 11, 15, 16x, 17, 18, 19, 20, 25}" it will output list boundary{} like the following:
The grouping mechanism in str2int() will strip away all non-digits, so be careful if you have values like 12x3 as it will be interpreted as 123 and not 12.
A geometric approach could also be an alternative.
I am admiring the flexibility of this tool and the genius of its users.
Thank you
I need a little time to test all these solutions. Thank you
I need a little time to test all these solutions. Thank you
Â
Â
A geometric approach could also be an alternative.
I need a little time to test all these solutions. Thank you