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
- Follow-Ups:
- Re: Position of Last Element in List
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Position of Last Element in List
- From: Carl Woll <carlw@wolfram.com>
- Re: Position of Last Element in List