MathGroup Archive 2008

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

Search the Archive

Position of Last Element in List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94130] Position of Last Element in List
  • From: Raffy <raffy at mac.com>
  • Date: Fri, 5 Dec 2008 05:33:50 -0500 (EST)

I'm looking for the fastest way to find the last position of an
element at level 1 in a list.

The fastest way, which is still extremely bloated and extremely slow,
appears to be:

lastPos[v_List,p_:True,default_:$Failed]:=(
$Temp=Position[Reverse[v],p,{1},1,Heads->False];
If[Length[$Temp]>0,$Temp[[1,1]],default]
);

Any suggestions?

Use the following code to compare against lastPos:

v = Range[1000000];
Do[lastPos[v,900000],{100}]//Timing


  • Prev by Date: FactorInteger bug ???
  • Next by Date: Re: NDSolve - Nice function but stiffness-problem
  • Previous by thread: Re: assignment problerm
  • Next by thread: Re: Position of Last Element in List