Re: sequential elements of list
- To: mathgroup at smc.vnet.net
- Subject: [mg119308] Re: sequential elements of list
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Mon, 30 May 2011 06:33:52 -0400 (EDT)
On 5/29/11 at 7:38 AM, Paul.McHale at excelitas.com (McHale, Paul) wrote: >Does anyone know of a way to use a pure function to access current >and next element of list with uses like Select[]? I know I might be >dazed and confused, but I thought there was a way. I.e. >mList={1,2,3,4,5,7,6,8}; >Select[mList, (#? > #??)&] >Where #? Is element N and #?? Is element N+1. I would expect the >previous code (assuming N?, N?? were valid) to return 7. It is not clear to me what you want for an output. If you want a list of all {mList[[n]],mList[[n+1]]} pairs, this is easily accomplished with Partition[mList,2,1] If you want a specific pair, say {4,5} from the list above, then there are a number of ways to accomplish this such as Cases[Partition[mList,2,1],{4,_}] or mList[[{#,#+1}]]&[Position[mList,4][[1,1]]]