Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10738 > unrolled thread
| Started by | Alexei Boulbitch <Alexei.Boulbitch@iee.lu> |
|---|---|
| First post | 2012-07-02 09:28 +0000 |
| Last post | 2012-07-02 09:28 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: how to make a list of rules with 2 other lists composed by different kinds of elements Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2012-07-02 09:28 +0000
| From | Alexei Boulbitch <Alexei.Boulbitch@iee.lu> |
|---|---|
| Date | 2012-07-02 09:28 +0000 |
| Subject | Re: how to make a list of rules with 2 other lists composed by different kinds of elements |
| Message-ID | <jsrpji$d33$1@smc.vnet.net> |
Dear all,
I want to generate a list composed by rules. That is,
I have two list
First one:
list1=={1, 2, 3}
The elements of this list are Integers.
Map[Head, list1] == {Integer, Integer, Integer}
Second one:
list2== {"file1", "file2", "file3"}
The elements of this list are Strings.
Map[Head, list2] == {String, String, String}
What I want is to have a new list like
list3== {1 -> "file1", 2 -> "file2", 3 -> "file3"}
Map[Head, list3] == {Rule, Rule, Rule}
Yes, of cause I can generate a list of rule manually. But what I have are
two big list of many elements and they are the output of other codes. So,
in real life this would be a part of big program. That is why I want to
generate the rule list automatically from list1 and list2. How could I do
this in a simple way? Thank you for your help.
Best regards,
Joug
Hi, Joug,
Try this:
list1 == {1, 2, 3};
list2 == {"file1", "file2", "file3"};
Thread[list1 -> list2]
{1 -> "file1", 2 -> "file2", 3 -> "file3"}
Or this:
Table[Rule[list1[[i]], list2[[i]]], {i, 1, Length[list1]}]
{1 -> "file1", 2 -> "file2", 3 -> "file3"}
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 top | Article view | comp.soft-sys.math.mathematica
csiph-web