Re: Replace list element based on a condition how to
- To: mathgroup at smc.vnet.net
- Subject: [mg106662] Re: Replace list element based on a condition how to
- From: dh <dh at metrohm.com>
- Date: Wed, 20 Jan 2010 06:50:12 -0500 (EST)
- References: <hj40od$sfg$1@smc.vnet.net>
Hi Kurt, without the superfluous braces and a condition on the pattern to prevent that it matches the whole list it works well: lst1 /. i_?NumberQ :> fncHourFix[i] Daniel Canopus56 wrote: > Q1. Is there a way to replace a list based on a condition? > > I have a list of integers - > > lst1 = {18, 19, 20, 21, 22, 23, 0, 1, 2, 3} > > that I would like to replace with the following rule - > > fncHourFix[h_] := If[(h - 6) < 0, h - 6 + 24, h - 6]; > > but the replace function - > > lst2 = lst1 /. {i_} :> fncHourFix[{i}] > > - bombs out. > > I've tried several variants. > > Any pointers would be appreciated. > > Thanks - Kurt > > > > >