4
$\begingroup$

How can I change form1 to form2

form1

{10000, 10004} -> {2, 2, 637}

form2

{10000 -> {2, 2, 637}, 10004 -> {2, 2, 637}}

One of my solutions

(Thread[MapThread[((*f/@*)#1 -> g@#2) &,   
                  List /@ List[{10000, 10004}, {2, 2, 637}]
                 ][[1]]
       ]) //. g -> Part
   {10000->{2,2,637},10004->{2,2,637}}

Have I taken a little detour?

$\endgroup$
6
$\begingroup$

There is the third argument for Thread:

Thread[ {10000, 10004} -> {2, 2, 637},  List, 1]
{10000 -> {2, 2, 637}, 10004 -> {2, 2, 637}}
| improve this answer | |
$\endgroup$
3
$\begingroup$
l = {10000, 10004} -> {2, 2, 637};
# -> l[[2]] & /@ l[[1]]
(* {10000 -> {2, 2, 637}, 10004 -> {2, 2, 637}} *)
| improve this answer | |
$\endgroup$
1
$\begingroup$

Let us define:

 form1 = {10000, 10004} -> {2, 2, 637};
f[x_] := x -> form1[[2]];

Then the second form is

 f /@ f1[[1]]

(*  {10000 -> {2, 2, 637}, 10004 -> {2, 2, 637}}  *)

Have fun!

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.