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


Groups > comp.soft-sys.math.mathematica > #15119

Re: Changing a list with the information of other

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!newspump.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From Alexei Boulbitch <Alexei.Boulbitch@iee.lu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Changing a list with the information of other
Date Wed, 3 Jul 2013 08:54:06 +0000 (UTC)
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <kr0ore$3fd$1@smc.vnet.net> (permalink)
Lines 50
Organization Time-Warner Telecom
NNTP-Posting-Date 03 Jul 2013 08:56:06 GMT
NNTP-Posting-Host dd7bedb9.news.twtelecom.net
X-Trace DXC=YYl[lZdjkX\P:Y0=`cYTT^C_A=>8kQj6]MOj3YM9`=aX7JgJ9dImUmUEFiONJ7[GoVW4hHDioan4^
X-Complaints-To abuse@twtelecom.net
X-Received-Bytes 2016
Xref csiph.com comp.soft-sys.math.mathematica:15119

Show key headers only | View raw


Good morning

I have the following (possibly very simple) problem.
I have a list, created using a Table

{{0, 1}, {1, w}, {2, 1 + w}, {3, 1 + 2 w}, {4, 2}, {5, 2 w}, {6, 2 + 2 w}, {7, 2 + w}}.

Then, using another Table, I created the list

{1, 1 + w, 2 + w, 2 w, 2, 2 + 2 w, 1 + 2 w, w}

Note that all these elements appear always in second place, in the ordered pairs of the first list. What I want is an instruction that allows to replace all these elements by the ones that appear first in the ordered pairs above. That is, I would like to replace this list by the new one

{0, 2, 7, 5, 4, 6, 3, 1}.

As you may guess this is only of interest when the lists are very big (with thousands of elements).

Thank you

Hi,
Try this:

lst1 = {{0, 1}, {1, w}, {2, 1 + w}, {3, 1 + 2 w}, {4, 2}, {5,
    2 w}, {6, 2 + 2 w}, {7, 2 + w}};
lst2 = {1, 1 + w, 2 + w, 2 w, 2, 2 + 2 w, 1 + 2 w, w};


f[a_] := Select[lst1, #[[2]] == a &][[1, 1]];
Map[f, lst2]

{0, 2, 7, 5, 4, 6, 3, 1}

Have fun, Alexei


Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu



Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Changing a list with the information of other Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2013-07-03 08:54 +0000
  Re: Changing a list with the information of other sigismond kmiecik <sigismond.kmiecik@wanadoo.fr> - 2013-07-03 22:03 +0000

csiph-web