Swapping strings

Hello
Is there a way to swap the names here:
image

for example: Instead of “Section -02Level 1” i want it to show “level1 Section -02”

some thing like that, example i convert to Section-Level01-02 ,…


def tolist(obj1):
	if hasattr(obj1,'__iter__') : return obj1
	else : return [obj1]
data = tolist(IN[0])
def ChangeStrPos(string):
    lst= string.split(" ")
    s,s2,s3 = [""]*3
    for i in lst:    
        if i.find("Level") != -1:
            for j in i:
                if j.isdigit():
                    s3 += j
                else: s2 += j
            print(s3)
            s += s2 +s3 + " "
        else: s +=i + " "
    return s
result = [ChangeStrPos(i) for i in data]
OUT = result
1 Like

Hi @NERDASORUS

Using nodes:

4 Likes

I think you just need to flip the X input into the Y, and the Y input into the X. :slight_smile:

2 Likes

An alternative with regex

import sys
import clr
import re
import System

tolist = lambda x : x if hasattr(x,'__iter__') and not isinstance(x, (str, System.String)) else [x]

lstStr = tolist(IN[0])

OUT = [re.sub(r'-(.+?)(Level.+$)', r'\g<2>\g<1>', str_eval) for str_eval in lstStr]
2 Likes