MathGroup Archive 2004

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

Search the Archive

labeling problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46430] labeling problem
  • From: Janos <janos.lobb at yale.edu>
  • Date: Wed, 18 Feb 2004 00:36:53 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Before I re-invent the wheel let me ask:

I need to assign  names to list elements in a nested list based upon 
their position in the nested list.  For example if I have a list:

lst = {{a,b},{c,d},e,f,{g,h,i},j,k,{l.m},{n,o,p},q,{r,s},{{t}}}

then
pos=Position[lst,{_,_,_}] will give me

{{5}.{9}}

Now, I am thinking to assign a unique name to the list elements on 
these positions, like p5={g,h,i} and p9={n,o,p}.  I did not find yet 
how to create variable names with concatenation auto-magically from 
program.  In other programming languages I can do something like this:

var="p"+NumToString[5]
&var={a,b,c}

and I could refer to it afterward as p5 and its value would be {a,b,c}. 
  The most handy would be if I could take just the name of the position 
and assign that to it, like:
For[i=1, i<=Length[pos], i++, NumberToName[pos[[i]]]=lst[[pos[[i]] ]] ]

and I would get:

five={g,h,i} and nine={n,o,p}.

Of course lst[[pos[[i]] ]] where' i' goes from 1 to 2 is somewhat doing 
it but it is a little bit complicated.

I looked the book and the online documentation but could not find a 
function called NumberToName which would do

NumberToName[5]
five

and vice versa

NameToNumber[five]
5

Is there such function or procedure in someone's drawer ?
If not, then what is the right way to get a unique variable name with 
some clear deterministic nature - like above - from Mathematica ?

Thanks ahead,
János

------------------------------------------
"There was a mighty king in the land of the Huns whose goodness and 
wisdom had no equal."
Nibelungen-Lied


  • Prev by Date: RE: Re: how to explain this weird effect? Integrate
  • Next by Date: Re: how to explain this weird effect? Integrate
  • Previous by thread: Re: Computing sets of equivalences
  • Next by thread: Re: labeling problem