# Creating pairs and specifying a name for them

I have a list as

list={-3/4, -3/4, 3/4, 3/4, -1/4, -1/4, -1/4, -1/4, -1/4, -1/4,
1/4, 1/4, 1/4, 1/4, 1/4, 1/4}


I want to create pairs with an added selected number in Range[3] in this method:

1-deleting same elements,
2-sorting by last,
4-specifying a name to the list

I use of Sort@Partition[list, 1] and after that use of Appendto but it doesn't work correctly, also the specifying a name for created data is more difficult!)

data1={{1,-3/4},{1, -1/4},{1, 1/4},{1,3/4}}
data2={{2,-3/4},{2, -1/4},{2, 1/4},{2,3/4}}
data3={{3,-3/4},{3, -1/4},{3, 1/4},{3,3/4}}

• Using data[ i ] is easier and more natural. Why do you want datai? Sep 11, 2015 at 12:19
• yes you are right, I can use of that Sep 11, 2015 at 12:30

o = Outer[List, Range@3, Union@list];
data[i_] := o[[i]]

data /@ Range@3

(*
{{{1, -(3/4)}, {1, -(1/4)}, {1, 1/4}, {1, 3/4}},
{{2, -(3/4)}, {2, -(1/4)}, {2, 1/4}, {2, 3/4}},
{{3, -(3/4)}, {3, -(1/4)}, {3, 1/4}, {3, 3/4}}}
*)


You could also just define data:

data[n_] := Thread[{n, Union@list}]


You could also use Tuples for a belisarius variant:

tup=GatherBy[Tuples[{Range@3, Union@list}], First];
dat[j_]:=tup[[j]]


but Outer seems neater for the original post.

• Please try list = RandomInteger[{1, 1000}, 1000000]; data[n_] := Thread[{n, Union@list}]; data[1]; // Timing Sep 11, 2015 at 14:57
• @belisarius thank you for the instructive comment. I did not know what the size of the problem this was going to be applied to. In retrospect, I should have more thoughtful and less tempted by terse looking. Always learning...:) Sep 11, 2015 at 22:23
• He! Yours was my first try! :) Sep 11, 2015 at 22:24