MathGroup Archive 1999

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

Search the Archive

Re: List Position

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15797] Re: [mg15740] List Position
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 7 Feb 1999 02:04:13 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On Fri, Feb 5, 1999, Harry flynn <harry.f at ukonline.co.uk> wrote:

>Can anyone tell me how I find the position in a list of the first value
>less than or equal to zero.
>For example, how can I get Mathematica to tell me that in the list
>{{1},{1},{2},{8},{-3}}
>that the first value of interest to me is position 5. Thanks in advance.
>Harry.
>
Here is one way to do it.

In[4]:=
findfirstnegative[l_]:=Position[l,Scan[If[#<0,Return[#]]&,l,Infinity]]

Now if you define

In[5]:= l={{1},{1},{2},{8},{-3}}

you get 

In[6]:=
findfirstnegative[l]
Out[6]=
{{5, 1}}

This actually works with any expression, not just a list:

In[7]:=
findfirstnegative[1/x]
Out[7]=
{{2}}

Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp/
http://eri2.tuins.ac.jp/



  • Prev by Date: RE: BracketingBar for output
  • Next by Date: Re: Finding real part (newbie question)
  • Previous by thread: Re: List Position
  • Next by thread: Re: List Position