Uneven list processing

I found this processing is very difficult for me. Almost I gave up. Did somebody wite such an AppleScript?

input: {“a”,{“b”,“c”}}

output: {“a_1”,{“b_1”,“c_1”}}

I gave up to use recursive call :slight_smile: This script works for limited condition data.

set aaList to {“1”, {“2”, “3”, “4”}}
set aRes to procList(aaList) of me
→ {“1_new”, {“2_new”, “3_new”, “4_new”}}

on procList(aList)
set outList to {}

repeat with i in aList
	set aClass to class of i
	
	if aClass = list then
		set aTmp to {}
		repeat with ii in i
			set tmpTmp to (ii as string) & "_new"
			set the end of aTmp to tmpTmp
		end repeat
	else
		set aTmp to (i as string) & "_new"
	end if
	
	set the end of outList to aTmp
end repeat
return outList

end procList

No, this is not a recursive subprogram. Here is the real recursive approach (the number of nested elements levels is unlimited):


set aaList to {"1", {"2", "3", "4"}}
set aaList to recursive_procedure(aaList)

on recursive_procedure(theList)
	repeat with i from 1 to (count of theList)
		set theItem to item i of theList
		if class of theItem = list then
			my recursive_procedure(theItem)
		else
			set item i of theList to (theItem & "_new")
		end if
	end repeat
	return theList
end recursive_procedure

Oh! Your code seems 65535 times better than my code! Thank!