Latex Set Notation

Yes, comparing LaTeX input to some original expression is not advisable. Not just because of the extra space you noted but also because while {1,2,3,5} and {5,3,2,1} are equivalent sets, they are not LaTeX-identical.

Checking for correctness is more involved. I found this discussion helpful.