• 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: AppleScript-Users Digest, Vol 11, Issue 117
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Users Digest, Vol 11, Issue 117


  • Subject: Re: AppleScript-Users Digest, Vol 11, Issue 117
  • From: Ted Wrigley <email@hidden>
  • Date: Wed, 19 Mar 2014 09:06:13 -0700


On Mar 19, 2014, at 4:24 AM, email@hidden wrote:

From: Alastair Leith <email@hidden>
Subject: Re: Sorting lists of strings and lists of lists in Applescript
Date: March 18, 2014 at 5:51:41 PM PDT
To: asu <email@hidden>


Hi Ted

That helps so much as I see how it works now, except I was hoping for sorting in the other 'dimension' if I can use that turn of phrase.

I was thinking about a list of lists where each child list is an individual record, from a table of similar records.

[…]

I could run transpose the lists into {{"adam","penny",…}, {"male","female",…}, {33, 43,…}} I guess. But is there a way to do it if I have lists of records like this, or even as lists with property labels (hashes) {name: "adam, gender: "male", age: 33}, etc etc  

transposing is the only way to go (unless you want to turn to ASObjC). you can do it like so:

———
set transposedList to transposeList(random_list_of_lists)
set sortedTransposedList to sortlist transposedList comparison 1 with respect to {2, 3, 1} with ascending and remove duplicates -- wrong interpretation!
set sorted_list_of_lists to transposeList(sortedTransposedList)

to transposeList(inList)
set outList to {}
repeat with thisSubList in inList
repeat with i from 1 to count of thisSubList
try
set end of item i of outList to item i of thisSubList
on error
set end of outList to {item i of thisSubList}
end try
end repeat
end repeat
return outList
end transposeList
———

If you want to sort records you’ll need to get a custom sorting algorithm. Google “A Dose of Sorts” which gives an assortment of pure-applescript sorting routines. The full package is TMI, but I’ve used the generic quicksort routine to sort records before.
 _______________________________________________
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

  • Prev by Date: Re: Fwd: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • Next by Date: Re: ID of a Disk
  • Previous by thread: Re: Fwd: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • Next by thread: folder copy
  • Index(es):
    • Date
    • Thread