• 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: Sorting lists of strings and lists of lists in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting lists of strings and lists of lists in Applescript


  • Subject: Re: Sorting lists of strings and lists of lists in Applescript
  • From: Ted Wrigley <email@hidden>
  • Date: Tue, 18 Mar 2014 17:01:15 -0700


On Mar 18, 2014, at 12:00 PM, email@hidden wrote:

From: Alastair Leith <email@hidden>
Subject: Sorting lists of strings and lists of lists in Applescript
Date: March 17, 2014 at 10:07:16 PM PDT
To: asu <email@hidden>

The dictionary description suggests this command will also sort a list of lists using the "with respect to" argument by prioritising the criteria with integers (presumably like a table sort in a spreadsheet app but no example or specification is provided).

You use this to sort a list of lists. in this form it’s a parallel sort: the command sorts the list at the given ‘with respect to’ index and rearranges the other lists in exactly the same way.  examples:

set l1 to {{"r", "q", "f", "c"}, {"a", "n", "z", "b"}, {"t", "a", "l", "q"}, {"p", "p", "z", "l"}}

sortlist l1 
— sorts list 1 (by default) and rearranges the remaining lists in parallel
--{{"c", "f", "q", "r"}, {"a", "b", "n", "z"}, {"a", "l", "q", "t"}, {"l", "p", "p", "z"}}

sortlist l1 with respect to 2
— sorts list 2 and sorts the remaining lists in parallel
--{{"r", "c", "q", "f"}, {"a", "b", "n", "z"}, {"t", "q", "a", "l"}, {"p", "l", "p", "z"}}

sortlist l1 with respect to {4, 3} without ascending
— sorts list 4 (descending) first (and the other lists in parallel) then resorts items 2 and 3 (where list 4 has matching P’s) by the descending sort order of those items in list 3
--{{"f", "r", "q", "c"}, {"z", "a", "n", "b"}, {"l", "t", "a", "q"}, {"z", "p", "p", "l"}}

sortlist l1 with respect to {4, 3} ascending {true, false}
— same as above except the initial sort is descending and the sub-sort is ascending.
--{{"c", "r", "q", "f"}, {"b", "a", "n", "z"}, {"q", "t", "a", "l"}, {"l", "p", "p", "z"}}

Hope that helps...
 _______________________________________________
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: Sorting lists of strings and lists of lists in Applescript
      • From: Alastair Leith <email@hidden>
  • Prev by Date: Re: Sorting lists of strings and lists of lists in Applescript
  • Next by Date: Re: Sorting lists of strings and lists of lists in Applescript
  • Previous by thread: Re: Sorting lists of strings and lists of lists in Applescript
  • Next by thread: Re: Sorting lists of strings and lists of lists in Applescript
  • Index(es):
    • Date
    • Thread