The expected result you showed is different even if you do sort the results. In the input you have one element %{position: 1} and in your expected results there are two elements.
Enum.group_by keeps the input order on the lists it creates for each group. The map keys are not sorted because maps are not an ordered data structure. The order is an implementation detail of the runtime.
EDIT: If you need sort the lists, you can either sort the input list because Enum.group_by keeps that order. Or you can sort each individual list in the result by doing this: Enum.into(result, %{}, fn {key, list} -> {key, Enum.sort(list)} end).
Thanks. But i don´t really get it. Where do you see only one element? Every element contains position and question.
I don´t see how Enum.into... can achieve the expected result. I don´t want to sort the lists inside the elements but rather the result as a whole. For example, if i have a question with a position 1 like this: %{position: 1, question: "Question2"} i need the the Question2 to be on top of every other Question with a lower position after the questions have been grouped.