make list with a loop funcion

I do a loop on a existing list.
there are multiple returns and I want to create a new list of those returns

for example:

set my_list to {"abc", "defg", "hia", "jklmno"}
repeat with i from 1 to count of my_list
	set MyItem to item i of my_list
	if MyItem contains "a" then
		
		display dialog " " & MyItem & " "
		
		
	end if
end repeat

how do I create the new sublist?

Here’s one way. :slight_smile:


set my_list to {"abc", "defg", "hia", "jklmno"}
set newList to {}
repeat with i from 1 to count of my_list
	set MyItem to item i of my_list
	if MyItem contains "a" then
		copy MyItem to end of newList
	end if
end repeat

When I do a

display dialog " " & newList & " "

I get one word “abchia” in stead of “abc, hia”

set my_list to {"abc", "defg", "hia", "jklmno"}
set newList to {}
repeat with i in my_list
	set MyItem to i as text
	if MyItem contains "a" then
		copy MyItem to end of newList
	end if
end repeat
set oldtid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", "
display dialog " " & newList as text
set AppleScript's text item delimiters to oldtid
return newList

Hi.

essentially means “as string”, because that command’s leftmost item determines the result’s class; your item is a space”an empty string. The second space at the end isn’t actually doing anything.

Thanks haolesurferdude, that solved something I was trying to do.