You don't have to write arr[0:i] every time if you write arr[:i], the interpreter already knows the index starts from 0. It's just a neat little detail for cleaner code!
Thanks for the feedback... I didnt real how sloppy was doing it! I was stuck on figuring out the distinction between left and right, so i was printing out the sum for every position until it clicked... I just didnt take the time refine it.
this solution covers less lines but requires multiple calls to a function (sum), although python is wonderful for providing many functions that make our work easier, sometimes you do not have to abuse them.
You don't have to write arr[0:i] every time if you write arr[:i], the interpreter already knows the index starts from 0. It's just a neat little detail for cleaner code!
Good solution bro
here
Doesn't this code do excess work?
i like the use of a comprehension here.
r is a list. If this list if not empty (ie len(r) > 0) then return first element (r[0]). It not then return integer -1
the last line
return r[0] if r else -1
high, I started coding a month ago and couldn't find the answer to my question on google.
what are you telling the computer with this? return R if R exists; if R is not None?
Thanks for the feedback... I didnt real how sloppy was doing it! I was stuck on figuring out the distinction between left and right, so i was printing out the sum for every position until it clicked... I just didnt take the time refine it.
this solution covers less lines but requires multiple calls to a function (sum), although python is wonderful for providing many functions that make our work easier, sometimes you do not have to abuse them.