Re: Sorting a List of Lists
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