• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How do I make words list from two lists?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How do I make words list from two lists?
      • From: Shane Stanley via AppleScript-Users <email@hidden>
    • Re: How do I make words list from two lists?
      • From: Deivy Petrescu via AppleScript-Users <email@hidden>
  • Prev by Date: Re: System Events keystroke altering variable case
  • Next by Date: Re: How do I make words list from two lists?
  • Previous by thread: Re: System Events keystroke altering variable case
  • Next by thread: Re: How do I make words list from two lists?
  • Index(es):
    • Date
    • Thread