Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6396 > unrolled thread

Re: Pattern to match element in nested list

Started byBob Hanlon <hanlonr357@gmail.com>
First post2011-11-12 12:34 +0000
Last post2011-11-12 12:34 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Pattern to match element in nested list Bob Hanlon <hanlonr357@gmail.com> - 2011-11-12 12:34 +0000

#6396 — Re: Pattern to match element in nested list

FromBob Hanlon <hanlonr357@gmail.com>
Date2011-11-12 12:34 +0000
SubjectRe: Pattern to match element in nested list
Message-ID<j9lp45$lbu$1@smc.vnet.net>
data = {{"Smith, Tim", 3}, {"Wheres,Waldo", 4},
   {"Muffet, LilMiss", 0}, {"Brown, Charlie", 1},
   {"X, Doctor", 0}};

Cases[data, {_, 0}]

{{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}

Select[data, Last[#] == 0 &]

{{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}

data /. {_, _?Positive} :> Sequence[]

{{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}

DeleteCases[data, {_, _?Positive}]

{{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}

Pick[data, data[[All, 2]], 0]

{{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}


Bob Hanlon


On Fri, Nov 11, 2011 at 4:54 AM, JasonE <ebaughjason@gmail.com> wrote:
> This is pretty basic and I am surprised at myself that I can't figure
> this out, but I guess its where I am at.
>
> What pattern would pick students with a score of zero out of this list
> (which is {"student", score}):
>
> {{"Smith, Tim",3},{"Wheres,Waldo",4},{"Muffet, LilMiss",0},{"Brown,
> Charlie",1},{"X, Doctor",0}}
>
>
>
> Thanks,
> Jason
>
> Contact: jasonebaugh@jasonebaugh.info
> Blog: www.jasonebaugh.info/wordpress/
> LinkedIn: www.linkedin.com/in/jasonebaugh
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web