Suppose that i have a list in this format=
$list=\{ \{a,obj1 \} ,\{c,obj2 \}, \{a,obj3 \}, \{b,obj4 \} \dots\}$
I want to construct a new list in this way:
$ newlist= \{ \{ \{a,obj1\} , \{a,obj3\} ... \}, \{ \{b,obj4\} , \{b,obj5\} ... \} ...\} $
This is, the new list must have sublist in which the first element of each sub-element is the same. In this way we have that for example, the first element of $newlist$ is formed by all the pairs in the form $\{a, [] \}$, the second element is formed by all the pairs in the form $\{b, [] \}$ ...etc.
My current approach is the following:
- Use $elements=Union[list[[All,1]] ]$ to get all different first-elements.
- Use $Select$ to get all elements of $list$ that has the same first-element extracted from $elements$.
- Construct a new list combining the two points.
What I whant is a "clever" functional-programming way to achieve this using the fewest functions possible.
I believe that this is an interesting question for people that are learning functional-programming (as me, for example).