Re: Pick function
- To: mathgroup at smc.vnet.net
- Subject: [mg62936] Re: [mg62906] Pick function
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 9 Dec 2005 05:10:15 -0500 (EST)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
The problem is caused by the presence of the Plus, i.e., g+h l = {1, a -> b, x, c -> 1, d -> e + f, g + h}; l2=Range[Length[l]]; Cases[l,_Rule] {a -> b, c -> 1, d -> e + f} Pick[l2,l,_Rule] {2, 4, 5} l = Most[l] {1, a -> b, x, c -> 1, d -> e + f} Pick[l,l,_Rule] {a -> b, c -> 1, d -> e + f} Pick[{g+h},{g+h},_Rule] {0} Bob Hanlon > > From: Zdenek Buk <zdenek at buk.cz> To: mathgroup at smc.vnet.net > Date: 2005/12/08 Thu AM 12:04:56 EST > Subject: [mg62936] [mg62906] Pick function > > Hi All, > > I have found a strange behavior of the "Pick" function. > > Testing data: > ------------ > In[1]:= > l = {1, a -> b, x, c -> 1, d -> e + f, g + h} > > Out[1]:= > {1, a -> b, x, c -> 1, d -> e + f, g + h} > > In[2]:= > l2=Table[i,{i,Length[l]}] > > Out[2]= > {1,2,3,4,5,6} > > > Now try to select the "Rules": > ----------------------------- > In[3]:= > Cases[l,x:(_->_)] > > Out[3]= > {a->b,c->1,d->e+f} > > OK, this is what I expected. > > but... > > Try to use the Pick function: > ---------------------------- > > In[4]:= > sel1=Pick[l,l,_->_] > > Out[4]= > {a->b,c->1,d->e+f,0} > > In[5]:= > sel2=Pick[l2,l,_->_] > > Out[5]= > {2,4,5} > > > As you can see, the the first command returned 4 items, but the second > command returned only 3 items (as expected). > I really don't understand why there is the last "0" value in "sel1" list. > > I expected, that "Pick[l,l,_->_]" command should return: > "{a->b,c->1,d->e+f}". > > > Is here somebody who can explain this strange behavior for me, please? > > > Zdenek Buk > >