• 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
Re: How do I make words list from two lists?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I make words list from two lists?


  • Subject: Re: How do I make words list from two lists?
  • From: Deivy Petrescu via AppleScript-Users <email@hidden>
  • Date: Sun, 22 Sep 2019 09:50:28 -0400


> On Sep 22, 2019, at 08:35 , Noriaki Fujita via AppleScript-Users
> <email@hidden> wrote:
>
> 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.
> _______________________________________________


If I understood what you want, this seems to do the job:

<script>
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}
set wordList to {}
set c to 1
repeat with k from 1 to count createcList(bList)
        set d to item k of createcList(bList) as number
        set end of wordList to (items c thru (c + d - 1) of alist) as string
        set c to c + d
end repeat
return wordList


on createcList(lista)
        set cList to {}
        repeat with j from 1 to count lista
                set bitm to contents of item j of lista
                if j = 1 then
                        set end of cList to {1}
                else
                        if bitm = (item (j - 1) of lista) then
                                set (item -1 of cList) to (item -1 of cList) + 1
                        else
                                set end of cList to 1
                        end if
                end if
        end repeat
        return cList
end createcList


</script>

cList in this case returns the following for this example: {3,5,5,3}
The length of cList gives the number of words and each item the length of each
word.






 _______________________________________________
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

References: 
 >How do I make words list from two lists? (From: Noriaki Fujita via AppleScript-Users <email@hidden>)

  • Prev by Date: How do I make words list from two lists?
  • Next by Date: Re: How do I make words list from two lists?
  • Previous by thread: How do I make words list from two lists?
  • Next by thread: Re: How do I make words list from two lists?
  • Index(es):
    • Date
    • Thread