Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #15935 > unrolled thread
| Started by | Bob Hanlon <hanlonr@cox.net> |
|---|---|
| First post | 2011-02-10 10:23 +0000 |
| Last post | 2011-02-10 10:23 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Sorting nested lists with strings Bob Hanlon <hanlonr@cox.net> - 2011-02-10 10:23 +0000
| From | Bob Hanlon <hanlonr@cox.net> |
|---|---|
| Date | 2011-02-10 10:23 +0000 |
| Subject | Re: Sorting nested lists with strings |
| Message-ID | <ij0eb7$9f0$1@smc.vnet.net> |
list = {{"Paul", 48}, {"Paul", 23}, {"Amanda", 55}, {"Carl", 32}};
Sort defaults to using the first element
Sort[list]
{{"Amanda", 55}, {"Carl", 32}, {"Paul", 23}, {"Paul", 48}}
SortBy[list, First]
{{"Amanda", 55}, {"Carl", 32}, {"Paul", 23}, {"Paul", 48}}
Sort[list, OrderedQ[{#1, #2}] &]
{{"Amanda", 55}, {"Carl", 32}, {"Paul", 23}, {"Paul", 48}}
Bob Hanlon
---- Paperorbifold <kgodelNOSPAM@liberoNOSPAM.it> wrote:
=============
I've a nested list of this kind:
list={{"Paul",23},{"Amanda",55},{"Carl",32},...}
Suppose I want to perform an alphabetic sort on the first element. Which is
the condition I've to write in Sort[list,...]?
Actually Sort[list] automatically operates on the second element.
Thanks.
--
...and I will make them pay for\nwhat they've done! (J.L. Picard)
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web