parts = ["M10", "S2", "M5", "S2", "B1"]

result = sorted(set(parts), key=lambda x: (int(x[1:]), x[0]))

print(result)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: