num = [100,1,82,-1]
print(sorted(num))
The above piece of code give the following output: [-1, 1, 82, 100].
However, I need it to be like [-1,1,82,100].
But so far I have been unable to figure out why does Python add whitespaces in a list with any kind of list operation!
Even a simple addition, or list methods like extend(), sort(), etc provide an output with leading whitespaces.
Although they shouldn't really matter, I am trying to solve a leetcode question, where my answer is getting rejected due to these leading whitespaces.
You can create a custom list type like below and then override how it is
printed, if necessary for debugging purposes:And if needed, you could also generalize that into a helper function, to eliminate minor overhead of a new type itself: