MathGroup Archive 2010

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

Search the Archive

Re: Select list elements and exchange them

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109821] Re: Select list elements and exchange them
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Wed, 19 May 2010 07:02:42 -0400 (EDT)
  • References: <hstp64$mbi$1@smc.vnet.net>

ishii.mitsuo.titanium at nsc.co.jp wrote:

> Hi
>
> I have a problem.
>
>
> I have a list.
>
> testList={ {11,{2,3}},{21,{3,4}},{34,{5,6}},{51,{7,8}} }
>
> 1) From this list, select any element list such as {x,{3,4}},
>
>  where X is an arbitrary number. 
>
> In general, position of {x,{3,4}} in "testList" is not fixed.
>
> 2) Select any element list such as {x,{3,4}} and then  exchange {x,{3,4}} to {100,{3,4}}.
>
> 3)Make a new list finally. 
>
> testListNew={ {11,{2,3}},{100,{3,4}},{34,{5,6}},{51,{7,8}} }
>
> Please teach me how to solve.
>
> Thanks in advance.
>
> Mitsuo Ishii
>

First search, where the member is

pos=Position[testList,{_,{3,4}}]

newlist=ReplacePart[testList, pos->{100,{3,5}}]

-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: Re: Select list elements and exchange them
  • Next by Date: Re: Select list elements and exchange them
  • Previous by thread: Re: Select list elements and exchange them
  • Next by thread: Re: Select list elements and exchange them