Replace elements in structured list

*To*: mathgroup at smc.vnet.net*Subject*: [mg99062] Replace elements in structured list*From*: replicatorzed at gmail.com*Date*: Sat, 25 Apr 2009 04:52:34 -0400 (EDT)

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

**Follow-Ups**:**Re: Replace elements in structured list***From:*Adriano Pascoletti <adriano.pascoletti@dimi.uniud.it>