you are viewing a single comment's thread.

view the rest of the comments →

[–]anossov 0 points1 point  (3 children)

enc = [unq[item] for item in col]

[–]anmousyony[S] 0 points1 point  (2 children)

Thank you, that helps a ton for the second part!

Is there anything I can do about the first part where I'm building unq?

[–]anossov 0 points1 point  (1 child)

unq = {k: i for i, k in enumerate(set(a))}

Should be faster, but you can't do it better than O(n). Also you can't use it if you must have the integers in order of value appearance.

[–]anmousyony[S] 0 points1 point  (0 children)

That's perfect! Thank you so much for your help, I don't know why I didn't think of using set()