• 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: Graff <email@hidden>
  • Date: Wed, 07 Jul 2004 11:40:03 -0400

How do you want to sort the items? Do you want to combine them all into one sorted list, or do you want to sort each sublist and leave the items in their sublists? Once the sublists are sorted how do you want to sort the meta-list - by first item, by last item, by some other criteria?

Basically what you are looking at is some sort of nested loop. Lets say you want to sort the lists by sorting each sublist alphabetically and then sorting the meta-list by first item:
----
set nestedList to {{"b", "d", "a"}, {"the", "lazy", "dog"}, {"a", "sunny", "day"}, {"to", "be", "or", "not", "to", "be"}}

-- bubble sort each list
repeat with theList in nestedList
set theSize to length of theList
repeat with i from 1 to theSize
repeat with j from 2 to (theSize - i + 1)
if ((item (j - 1) of theList) > (item j of theList)) then
set temp to (item (j - 1) of theList)
set (item (j - 1) of theList) to (item j of theList)
set (item j of theList) to temp
end if
end repeat
end repeat
end repeat

-- bubble sort outside list by first item
set theSize to length of nestedList
repeat with i from 1 to theSize
repeat with j from 2 to (theSize - i + 1)
if ((first item of item (j - 1) of nestedList) > (first item of item j of nestedList)) then
set temp to (item (j - 1) of nestedList)
set (item (j - 1) of nestedList) to (item j of nestedList)
set (item j of nestedList) to temp
end if
end repeat
end repeat

nestedList
--> {{"a", "b", "d"}, {"a", "day", "sunny"}, {"be", "be", "not", "or", "to", "to"}, {"dog", "lazy", "the"}}
----
- Ken

On Jul 7, 2004, at 10:29 AM, email@hidden wrote:

Hi all, I am trying to sort a list of lists. I have been through the
archives and have found the threads on 'QuickSortOnItem ' handler and have
compiled it but I get a stack overflow when running it. Could someone
point me in the right direction?
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Sorting a list of Lists (From: email@hidden)

  • Prev by Date: How to return error message text from do shell script
  • Next by Date: Re: Getting the default language with AppleScript
  • Previous by thread: Sorting a list of Lists
  • Next by thread: Re: Sorting a list of Lists
  • Index(es):
    • Date
    • Thread