Feb-03-2021, 05:24 PM
Two other nitpicks.
There is no reason for the else: If len(ls) == 1 you will never get past the "return ls". There is no reason for the protection provided by the else, and no reason to lose the indent space.
Never use lower case L or upper case O as variable names. It is too easy to mistake this as 1 or 0.
Use better function and variable names. This should clearly be called mergesort or merge_stort. The left and right sides should be called left and right, not l and r. When you begin using a linter it is going to complain, A lot. May as well develop good habits early on.
https://www.python.org/dev/peps/pep-0008/
And don't put multiple statements on one line. Not even beak.
There is no reason for the else: If len(ls) == 1 you will never get past the "return ls". There is no reason for the protection provided by the else, and no reason to lose the indent space.
def ms(ls): if len(ls)==1: #base case return ls else: mid = len(ls)//2 l = ms(ls[:mid]) r = ms(ls[mid:]) nu=[] #return listIndent should be 4, not 2. You code would be easier to read if the blocks were easier to see.
Never use lower case L or upper case O as variable names. It is too easy to mistake this as 1 or 0.
Use better function and variable names. This should clearly be called mergesort or merge_stort. The left and right sides should be called left and right, not l and r. When you begin using a linter it is going to complain, A lot. May as well develop good habits early on.
https://www.python.org/dev/peps/pep-0008/
And don't put multiple statements on one line. Not even beak.
if len(r)==0: break