Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9467
| From | Alexei Boulbitch <Alexei.Boulbitch@iee.lu> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: addRule |
| Date | 2012-04-06 09:51 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jlmebt$m55$1@smc.vnet.net> (permalink) |
Hello,
I have these data
{{1, {38, 35, 37}}, {2, {21}}, {3, {24, 14}}}
and I want
{[1->38,1->35,1->37},{2->21},{3->24,3->14}}
The solution is simple when list of data have the same length
But what is the solution for my example
Thanks
Andrew
Hi, Andrew,
Try this:
lst = {{1, {38, 35, 37}}, {2, {21}}, {3, {24, 14}}};
Table[Rule[lst[[i, 1]], #] & /@ lst[[i, 2]], {i, 1, Length[lst]}]
{{1 -> 38, 1 -> 35, 1 -> 37}, {2 -> 21}, {3 -> 24, 3 -> 14}}
or this:
g[{a_, list_List}] := Rule[a, #] & /@ list;
Map[g, lst]
{{1 -> 38, 1 -> 35, 1 -> 37}, {2 -> 21}, {3 -> 24, 3 -> 14}}
There should be also a better way, but I failed to guess fast.
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 | Find similar | Unroll thread
Re: addRule Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2012-04-06 09:51 +0000
csiph-web