MathGroup Archive 2009

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

Search the Archive

Re: Replace elements in structured list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99066] Re: Replace elements in structured list
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sun, 26 Apr 2009 01:36:55 -0400 (EDT)
  • References: <gsuivb$duh$1@smc.vnet.net>

Hi,

c = 1;
data /. _Integer :> c++

?

Regards
   Jens



replicatorzed at gmail.com wrote:
> Dear Group,
> 
> how would you solve this problem in an elegant and effective way?
> My aim is to get a list of consecutive numbers, starting from 1, AND
> to retain the structure of the original list as well.
> 
> In[49]:= data = {{1, {2, 2, 2, 2}, {2, 2, 2, 2}, 1}, {1, {2, 2, 2, 2},
> {2, 2, 2, 2}, 1}};
> 
> c = 1;
> 
> Replace[data, _?NumberQ :> c++, \[Infinity]]
> 
> Out[51]= {{37, {38, 39, 40, 41}, {42, 43, 44, 45},
>   46}, {47, {48, 49, 50, 51}, {52, 53, 54, 55}, 56}}
> 
> So the function should return a similar list, but starting at 1
> instead of 37.
> Now I must note that the original data can have fewer/more levels,
> elements, etc.
> 
> Thank you in advance,
> Istvan Zachar
> 


  • Prev by Date: Copy/paste selection of a pdf on Mac
  • Next by Date: Re: Is this solvable using Mathematica?
  • Previous by thread: Re: Replace elements in structured list
  • Next by thread: Is this solvable using Mathematica?