How do I parse lists within lists?

I have a script that generates a list within a list, similarly formatted to the example below. I’d like to use that list to make a new list with only colors, or only numbers.

I would expect the code below to return {"5, "20", "15"}, but it returns {"blue", "5"}.

set theList to {{"blue", "5"}, {"orange", "20"}, {"yellow", "15"}}

set colorList to item 1 of (every item of theList)

return colorList

How do I use this to make a new list by obtaining the first (or second, or third) part of every list within the bigger list? Such that I could get either

{"blue}, {"orange"}, {"yellow"} or

{"5}, {"20"}, {"15"}

This code below should do the job. In your case, “every item of the list” is equal to the list, NOT to the sublists within it.

Stan C.

set sublistItemIndex to 2
set indexedItems to getSublistItemsFromListOfSublists(theList, sublistItemIndex)

on getSublistItemsFromListOfSublists(theList, sublistItemIndex)
	set indexedItems to {}
	repeat with i from 1 to (count of theList)
		set end of indexedItems to item sublistItemIndex of item i of theList
	end repeat
	return indexedItems
end getSublistItemsFromListOfSublists```
1 Like

Wow, thank you so much. Worked like a charm. Bless you.