I want to convert the labels of my data from character to numerical as XGboost does not allow character. Is there a library to convert labels?

E.g. Y=['a','b','c','a','a','c','c','b','b','a'] should be converted to [0, 1, 2, 0, 0, 2, 2, 1, 1, 0]

Since I do not know how many different values are there in Y, I want to use some existing library to convert.

E.g. Y=['a','b','c','a','a','c','c','b','b','a'] should be converted to [0, 1, 2, 0, 0, 2, 2, 1, 1, 0]

Since I do not know how many different values are there in Y, I want to use some existing library to convert.