Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10565 > unrolled thread

Re: altering each member of a list that matches a certain pattern

Started byBill Rowe <readnews@sbcglobal.net>
First post2012-06-21 09:20 +0000
Last post2012-06-21 09:20 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: altering each member of a list that matches a certain pattern Bill Rowe <readnews@sbcglobal.net> - 2012-06-21 09:20 +0000

#10565 — Re: altering each member of a list that matches a certain pattern

FromBill Rowe <readnews@sbcglobal.net>
Date2012-06-21 09:20 +0000
SubjectRe: altering each member of a list that matches a certain pattern
Message-ID<jrup1d$fl0$1@smc.vnet.net>
On 6/20/12 at 3:51 AM, ebaughjason@gmail.com (Jason Ebaugh) wrote:

>I need to alter each member of a list that matches a certain
>pattern. However, I need the whole list back, in its original order.
>So Cases[] on its own doesn't do the trick.

>Here is a toy example that is analogous to my real problem: Put an
>asterisk on each value that is 10 or greater in the following list.

>list = RandomSample[Range[20], 20]

>Out[1]= {19, 16, 5, 13, 10, 20, 1, 3, 18, 8, 9, 6, 12, 7, 4, 15, 11,
>14, 2, 17}

>I came up with two ways to do this. However, I feel like I may be
>missing a simpler, single function way to do this.

>Method 1: If[# > 9, SuperStar[#], #] & /@ list

This seems to me to be a pretty simple method. Another approach
that you might see as simpler would be

list /. a_?(# > 9 &) -> SuperStar[a]

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web