How do I make words list from two lists?
How do I make words list from two lists?
- Subject: How do I make words list from two lists?
- From: Noriaki Fujita via AppleScript-Users <email@hidden>
- Date: Sun, 22 Sep 2019 21:35:48 +0900
Hello
I am thinking about how to make words list from two lists.
Please tell me how to do it.
—
Example)
set alist to {"H", "e", "l", "l", "o", "W", "o", "r", "l", "d"}
set bList to {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}
-->{"Hello", "World"}
or
set alist to {"T", "h", "e", "q", "u", "i", "c", "k", "b", "r", "o",
"w", "n", "f", "o", "x"}
set bList to {1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4}
-->{"The", "quick", "brown", "fox"}
alist is every character of paragraph
bList is filter index
alist and bList is same length
---
This is the method I thought of myself.
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set alist to {"T", "h", "e", "q", "u", "i", "c", "k", "b", "r", "o",
"w", "n", "f", "o", "x"}
set bList to {1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4}
-->{"The", "quick", "brown", "fox"}
set cList to unionAndSortList(bList as list)
-->{1, 2, 3,4}
set string_list to {}
repeat with n from 1 to count cList
set c to item n of cList
set aText to ""
repeat with i from 1 to count bList
set a to item i of alist
set b to item i of bList
if b is c then
set aText to aText & a
end if
end repeat
set end of string_list to aText
end repeat
return string_list
on unionAndSortList(theList)
set aArray to current application's NSArray's arrayWithArray:theList
set sortRes to ((aArray's
valueForKeyPath:"@distinctUnionOfObjects.self")'s
sortedArrayUsingSelector:"compare:")
return sortRes as list
end unionAndSortList
---
I want to make this simple code with NSPredicate.
N.F.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden