List numbering by a structure

Hi guys! Need your help. I need to create list numbering by the structure of another list

For example, I have a list of strings

13
13.10
13.10.50
13.10.50.20
13.10.50.20.10
13.10.50.20.20
14
14.10.40
14.10.40.30
14.10.40.30.60
14.10.40.30.70
14.10.40.30.80

And I want to create another list with the same structure

1
1.1
1.1.1
1.1.1.1
1.1.1.1.1
1.1.1.1.2
2
2.1
2.1.1
2.1.1.1
2.1.1.1.1
2.1.1.1.2
2.1.1.1.3

I will really appreciate any help on this case. Thanks

Hey,

Like this maybe? I’m not sure why 2.1.1.2 happens in your structure? Perhaps you want to add a sequence in there? :slight_smile:

Hope that helps,

Mark

1 Like

Thanks! Yep, tried almost the same approach previously. But I also need somehow to make it in a range.

for example

1
1.1
1.1.1
1.1.2
1.1.3
2
2.1.1
2.1.2
2.1.2.1
2.1.2.2

So you need a set of rules…

The first number increases everytime there is a number with no "."s

The second number is always 1.

The third number increases sequentially within the main numbers, as does the 4th…

If you play around with counts and sequences I’m sure you’ll get there :slight_smile:

Good luck :slight_smile:

Mark

1 Like

Another option would be to split the strings into sections and group them by value. Then you count how many unique values there are per section and increment that way.

@Mark.Ackerley the second number does not have to be always one, however in the structures @Andriy supplied there is no way for a one to generate in the second column, this could happen in a sequence like this though:

Input: 10  			=>  Output: 1
Input: 10.10  		=>  Output: 1.1
Input: 10.10.10  	=>  Output: 1.1.1
Input: 10.10.20  	=>  Output: 1.1.2
Input: 10.20  		=>  Output: 1.2
Input: 10.20.10  	=>  Output: 1.2.1
Input: 10.20.10.10 	=>  Output: 1.2.1.1
Input: 10.20.20  	=>  Output: 1.2.2
Input: 10.20.30  	=>  Output: 1.2.3
Input: 11  			=>  Output: 2
Input: 11.10  		=>  Output: 2.1
Input: 11.20  		=>  Output: 2.2
Input: 12  			=>  Output: 3
Input: 12.10  		=>  Output: 3.1
Input: 12.10.10  	=>  Output: 3.1.1

Hi @Andriy ,

See if the following snippet works:

def generate_paragraph_structure(strings):
    result = []
    counter = [0] * 10  # Counter to keep track of the number at each level
    
    for string in strings:
        dot_count = string.count('.')
        counter[dot_count] += 1
        counter[dot_count+1:] = [0] * (10 - dot_count - 1)
        paragraph = '.'.join(map(str, counter[:dot_count+1]))
        result.append(paragraph)
    
    return result


OUT = generate_paragraph_structure(IN[0])
Used Inputs
[
"13",
"13.10",
"13.10.50",
"13.10.50.20",
"13.10.50.20.10",
"13.10.50.20.20",
"14",
"14.10",
"14.10.40",
"14.10.40.30",
"14.10.40.30.60",
"14.10.40.30.70",
"14.20",
"14.20.10"];
1 Like

@Daan thank you very much! It has worked almost perfectly! The only thing - on my side 4th symbol shows 0 instead of 1

Before you have answered, I have created graph based on nodes. It works but it’s really huge (see Screenshot) :sweat_smile:

I need to learn more Python!

That’s because you are missing 1 level in between the current and previous value (or the current and next, dependant on how you see it). You’re jumping from 2 “.” to 4 “.”. At line 30 the output is as expected since the structure is incremental.

A simple fix would be to add a String.Replace node afterwards to replace all zeroes with ones:

Python Code
def generate_paragraph_structure(strings):
    result = []
    counter = [0] * 10  # Counter to keep track of the number at each level
    
    for string in strings:
        dot_count = string.count('.')
        counter[dot_count] += 1
        counter[dot_count+1:] = [0] * (10 - dot_count - 1)
        paragraph = '.'.join(map(str, counter[:dot_count+1]))
        result.append(paragraph)
    
    return result


OUT = generate_paragraph_structure(IN[0])

It could probably also be fixed within the Python Script, but I’m lazy and this works too.