MathGroup Archive 2010

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

Search the Archive

Re: Replace list element based on a condition how to


Hi,

your rule is wrong. There is no list with *one* element as {i_} 
suggests..

lst1 = {18, 19, 20, 21, 22, 23, 0, 1, 2, 3}
lst1 /. i_Integer :> If[(i - 6) < 0, i - 6 + 24, i - 6]
fncHourFix[h_] := If[(h - 6) < 0, h - 6 + 24, h - 6];
lst1 /. i_Integer :> fncHourFix[i]

Cheers
Patrick

On Tue, 2010-01-19 at 05:13 -0500, 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 
> 
> 
> 
>       
> 



  • Prev by Date: StringCases matching on portions of sublist?
  • Next by Date: Re: trouble with a Binet in a generalized Pell recursion
  • Previous by thread: Re: Replace list element based on a condition how to
  • Next by thread: Re: Re: Replace list element based on a