Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6399 > unrolled thread
| Started by | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| First post | 2011-11-12 12:36 +0000 |
| Last post | 2011-11-12 12:36 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Pattern to match element in nested list Bill Rowe <readnews@sbcglobal.net> - 2011-11-12 12:36 +0000
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Date | 2011-11-12 12:36 +0000 |
| Subject | Re: Pattern to match element in nested list |
| Message-ID | <j9lp8v$lfc$1@smc.vnet.net> |
On 11/11/11 at 4:54 AM, ebaughjason@gmail.com (JasonE) wrote:
>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}}
A couple of simple ways to get the desired result:
In[8]:= data = {{"Smith, Tim", 3}, {"Wheres,Waldo",
4}, {"Muffet, LilMiss", 0}, {"Brown,
Charlie", 1}, {"X, Doctor", 0}};
In[9]:= Cases[data, {__, 0}]
Out[9]= {{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}
In[10]:= Select[data, Last@# == 0 &]
Out[10]= {{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}
or if you wanted to do the same task via pattern matching:
In[11]:= data /. {__, _?Positive} :> Sequence[]
Out[11]= {{"Muffet, LilMiss", 0}, {"X, Doctor", 0}}
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web