sorting - Sort one list by the order of another list -
I need to sort a list according to the second list, but I do not know how this can be done.
For example: I can have a list (Just as an example, These are not real values) Then, the list should be sorted Any help would be greatly appreciated. If I think, one of the lists lists the sequence relative to all the elements in another list. Ie: This piece of code should work: a :
[C, B, G, E] <[A, B, C, D, E, F, G, B, C, D, E, F, G, ...]
a list is same as the list
b and so on Sorted:
[A, B, E, G]
& gt; Sort with order [5,1,2,3,4] [1,2,3,4,5,5,4,3,2,1] [5,5,1,1,2,2,3, 3, 4, 4]
Module sortwhit order where importable data. Map. M Limited as import data. Import Import Data. Ord Sort Wideorder :: Ord A = & gt; [A] - Order list - & gt; [A] - Source list - & gt; [A] Sort with order order = Sort by (compare gore order) where mill orderer = m.fundvith default (-1) k ordermap ordermap = M.fromList (zip order [0 ..])
Comments
Post a Comment