2
$\begingroup$

I am having problems to understand the association function. I have a list of lists containing numbers:

{{{0.494118, 0.678431, 0.882353, 1.}, {0.498039, 0.682353, 0.886275, 
   1.}, {0.505882, 0.686275, 0.882353, 1.}, {0.509804, 0.690196, 
   0.886275, 1.}, {0.521569, 0.694118, 0.886275, 1.}, {0.529412, 
   0.694118, 0.890196, 1.}, {0.533333, 0.698039, 0.886275, 
   1.}, {0.537255, 0.701961, 0.890196, 1.},...}}

and I would like something like this:

{{{0.494118, 0.678431, 0.882353, 1.}->1, {0.498039, 0.682353, 0.886275, 
   1.}->2, {0.505882, 0.686275, 0.882353, 1.}->3...}}

then, the final output should be {1,2,3,...}.

Could you please tell me which functions should I consider to get the final output? Many thanks

$\endgroup$
2
$\begingroup$
list = {{0.494118, 0.678431, 0.882353, 1.}, {0.498039, 0.682353, 
    0.886275, 1.}, {0.505882, 0.686275, 0.882353, 1.}, {0.509804, 
    0.690196, 0.886275, 1.}, {0.521569, 0.694118, 0.886275, 
    1.}, {0.529412, 0.694118, 0.890196, 1.}, {0.533333, 0.698039, 
    0.886275, 1.}, {0.537255, 0.701961, 0.890196, 1.}};

Thread[list -> Range@Length@list]

{{0.494118, 0.678431, 0.882353, 1.} -> 1, {0.498039, 0.682353, 0.886275, 1.} -> 2, {0.505882, 0.686275, 0.882353, 1.} -> 3, {0.509804, 0.690196, 0.886275, 1.} -> 4, {0.521569, 0.694118, 0.886275, 1.} -> 5, {0.529412, 0.694118, 0.890196, 1.} -> 6, {0.533333, 0.698039, 0.886275, 1.} -> 7, {0.537255, 0.701961, 0.890196, 1.} -> 8}

$\endgroup$
  • $\begingroup$ Many thanks, OkkesDulgerci! $\endgroup$ – Val Sep 22 at 22:57
3
$\begingroup$

You can also use MapIndexed:

MapIndexed[# -> #2[[1]] &, list]

{{0.494118, 0.678431, 0.882353, 1.} -> 1,
{0.498039, 0.682353, 0.886275, 1.} -> 2,
{0.505882, 0.686275, 0.882353, 1.} -> 3,
{0.509804, 0.690196, 0.886275, 1.} -> 4,
{0.521569, 0.694118, 0.886275, 1.} -> 5,
{0.529412, 0.694118, 0.890196, 1.} -> 6,
{0.533333, 0.698039, 0.886275, 1.} -> 7,
{0.537255, 0.701961, 0.890196, 1.} -> 8}

$\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.