I forget what sorting algorithm I used, but I once implemented scanline triangle rasterization in Python just for fun. But apparently the traditional algorithm used for sorting by X coordinate is bubble sort, since the leftmost X coordinate of any given triangle normally doesn't change much from scanline to scanline.
https://en.wikipedia.org/wiki/Scanline_rendering