MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pattern to match element in nested list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122840] Re: Pattern to match element in nested list
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Sat, 12 Nov 2011 07:33:19 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201111110954.EAA08487@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 at 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 at jasonebaugh.info
> Blog: www.jasonebaugh.info/wordpress/
> LinkedIn: www.linkedin.com/in/jasonebaugh
>



  • Prev by Date: Re: Question for Partial differential summationseries
  • Next by Date: Re: Domain of a function
  • Previous by thread: Re: Pattern to match element in nested list
  • Next by thread: Re: Pattern to match element in nested list