Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: addRule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125883] Re: addRule
  • From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
  • Date: Fri, 6 Apr 2012 05:51:27 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

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 at iee.lu







  • Prev by Date: Re: numerical integration
  • Next by Date: Re: ListPlot question
  • Previous by thread: Re: addRule
  • Next by thread: 3D Rotations