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


Groups > comp.soft-sys.math.mathematica > #9424 > unrolled thread

Re: addRule

Started byUlrich Arndt <ulrich.arndt@data2knowledge.de>
First post2012-04-05 09:48 +0000
Last post2012-04-05 09:48 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: addRule Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2012-04-05 09:48 +0000

#9424 — Re: addRule

FromUlrich Arndt <ulrich.arndt@data2knowledge.de>
Date2012-04-05 09:48 +0000
SubjectRe: addRule
Message-ID<jljpqa$coe$1@smc.vnet.net>
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
> 

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web