Looping with range (while loop)

I have a list of json-formatted documents I need to consolidate into list of strings, each shorter than a preset number of characters. Hence, I need loop through the list, joining the elements until the length of string reaches certain limit, something like:

[
final_list =
for doc in list :
while lenght(jsondecode(i) < limit :
append (join(",", concatenate(doc, doc[index+1])), final_list)
]

So, the goal is: split this list into subelements where none of them contains more than N number of characters. Can anyone help, please?

contains can be used to test if a string is already part of a list.

distinct can be used to remove duplicates.

Hi ausmartway,

not sure I explained very well what I’m trying to do, but I need to move the index forward for the elements that had already dealt with - don’t think that either distinct or contains would help there.