• 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 a List of Lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting a List of Lists


  • Subject: Re: Sorting a List of Lists
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 27 Apr 2013 18:21:03 -0500

On Apr 27, 2013, at 16:49, Marconi <email@hidden> wrote:
> I have a list of lists with two items in each list.
> ...
> I need to sort these on the first datum so that the above list would come out:
>
> {"2010-07-11", "some other text here"}
> {"2012-12-22", "some different here"}
> {"2013-04-01", "some text here"}
______________________________________________________________________

Hey Marconi,

Personally I'd use the Satimage.osax and this script:

-------------------------------------------------------------------------------------------

set _list to {{"2013-04-01", "some text here"}, {"2010-07-11", "some other text here"}, {"2012-12-22", "some different here"}}

set AppleScript's text item delimiters to " • "

repeat with i in _list
	set contents of i to (i as text)
end repeat

set _list to sortlist _list

repeat with i in _list
	set contents of i to (text items of i)
end repeat

_list

-------------------------------------------------------------------------------------------

This one uses the shell rather than the Satimage.osax:

-------------------------------------------------------------------------------------------

set _list to {{"2013-04-01", "some text here"}, {"2010-07-11", "some other text here"}, {"2012-12-22", "some different here"}}

set AppleScript's text item delimiters to " • "

repeat with i in _list
	set contents of i to (i as text)
end repeat

set AppleScript's text item delimiters to linefeed
set _list to _list as text

set _list to text items 1 thru -2 of (do shell script "sort -g <<< " & quoted form of _list without altering line endings)

set AppleScript's text item delimiters to " • "

repeat with i in _list
	set contents of i to (text items of i)
end repeat

_list

-------------------------------------------------------------------------------------------

Both are much faster than the bubble-sort.

Approximately 0.025 seconds for a 200 item list on my MacBook Pro.

--
Best Regards,
Chris


 _______________________________________________
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: 
 >Sorting a List of Lists (From: Marconi <email@hidden>)

  • Prev by Date: Re: Sorting a List of Lists
  • Next by Date: how to script QT to export file to mp4 format?
  • Previous by thread: Re: Sorting a List of Lists
  • Next by thread: Re: Sorting a List of Lists
  • Index(es):
    • Date
    • Thread