Re: Finding position of an element in a list:

*To*: mathgroup at smc.vnet.net*Subject*: [mg84022] Re: Finding position of an element in a list:*From*: Tom Burton <news at brahea.com>*Date*: Thu, 6 Dec 2007 07:29:12 -0500 (EST)

It should be clear to you that dropOuterBraces returns a string. There are no strings in your list, so of course Position returns the empty set. By default, Mathematica does not quote outputed strings, allowing your confusion. To avoid future confusion, you can in the Options Inspector set the global parameter ShowStringCharacters -> True You could modify dropOuterBraces to yield a number (see ToExpression), however, it's far easier to do this: eval = First[n1] Tom When responding, please replace news with my first initial and full last name, as one word. Tom Burton > ... Suppose we have a list, xlis, having some elements, and I have > to find one nearest value I am interested in that list. In the > below example, I wanted to find the position of a number belonging > to list and close to 6 (which is 5.5 located at 7th). > > I can do this: > > xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1]...