• 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: sort these records?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sort these records?


  • Subject: Re: sort these records?
  • From: email@hidden
  • Date: Wed, 28 May 2008 16:16:40 -0500

Michelle Steiner writes:

On May 28, 2008, at 1:24 PM, Hudson Barton wrote:

I need to sort a long list of records whose structure is like this:

{{owner:"Dom",cats:{"Sane","Crazy"}},{owner:"Andy",cats: {"Hip","Dip"}}}

Sort by "owner" alphabetically.

Suggestions?

Records are unsorted by nature; you can't sort them.


-- Michelle

--
I'm at an age where I can satisfy my wants without too many guilt feelings.



Michelle it is a list of records, thus it can be sorted.


Hudson, here is a beginning it is not optimized,that is, it is good for short lists, and it will give you an empty record at the end or at the beginning, it is easy to remediate that, so ... it is up to you.

<script>(*)
set rec to {{owner:"Dom", cats:{"Sane", "Crazy"}}, {owner:"Andy", cats:{"Hip", "Dip"}}}
sort(rec)


on sort(l)
if (count of l) < 2 then return l
set m to item 1 of l
set rl to rest of l
set l2 to {}
set l1 to {}
repeat with j in rl
set j to contents of j
if owner of j > owner of m then
set l2 to l2 & j
else
set l1 to l1 & j
end if
end repeat
return sort({l1}) & {m} & sort({l2})
end sort
</script>


(*)based on a sort routine posted by Emmanuel Levy

_______________________________________________
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: sort these records?
      • From: "Mark J. Reed" <email@hidden>
References: 
 >as alias bug? (From: Philip Aker <email@hidden>)
 >Re: as alias bug? (From: deivy petrescu <email@hidden>)
 >Re: as alias bug? (From: Michelle Steiner <email@hidden>)
 >sort these records? (From: Hudson Barton <email@hidden>)
 >Re: sort these records? (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: sort these records?
  • Next by Date: Re: sort these records?
  • Previous by thread: Re: sort these records?
  • Next by thread: Re: sort these records?
  • Index(es):
    • Date
    • Thread