Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: addRule
Replies: 9   Last Post: Apr 6, 2012 5:51 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Ulrich Arndt

Posts: 53
Registered: 10/1/09
Re: addRule
Posted: Apr 5, 2012 5:48 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

maybe there are more elegant ways but this will do

dat = {{1, {38, 35, 37}}, {2, {21}}, {3, {24, 14}}}
Clear[addRule]
addRule[{a_Integer, b_List}] :=
Apply[Rule, Transpose[{ConstantArray[a, Length[b]], b}], {1}];
Map[addRule, dat]

Ulrich

Am 04.04.2012 um 10:31 schrieb clansa:

> 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
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.