Question: Sorting one list according to another list

Hi

First question is, given a list of some positive integers, how can I normalize this list? Normalize here is in the sense that, for example, if 

L := [1,3,4,4,5,7,7,7,8]

then there really are only 6 different integers appear, so I would like to assign each part an integer from 1 to 6 in ascending order. So 1 becomes 1, 3 becomes 2, 4 becomes 3, 5 becomes 4, 7 becomes 5 and so on. Normalized list will be

NormalizedL := [1,2,3,3,4,5,5,5,6]

 

Second question is given a list, let's say [1,3,1,3,2,2,4,4], how can I normalize it in a similar way but now we assign each integer upon occurrence of a part. So [1,3,1,3,2,2,4,4] will be [1,2,1,2,3,3,4,4]. This is necessary for me because lists have repeating parts. 

Another example will be [2,4,4,1,2,2,3,3] will be [1,2,2,3,1,1,4,4]. 

Thank you 

Please Wait...