Ad
  • Custom User Avatar

    i believe it works due to fact that value of arr[:i+1] is not being called as ending value is not included in a slice of list.

    Example:
    arr = [1,2,3,4,5]
    len(arr) = 5
    [i for i in range(5)] --> i = [0,1,2,3,4]
    len(arr) --> IndexError
    arr[:i] -> arr[:4] --> [1,2,3,4]
    arr[:i+1] -> arr[:5] --> [1,2,3,4,5]