educative.io

Educative

Why is there a different output for the last two lists?

Hello,
I don’t understand why there is a different output for the last two lists:

A = [1, 2, 3, 4, 5]

and

A = [5, 4, 3, 2, 1]

I think the output should be the same: either None for both or 5 for both.
In this block of code:

mid_left = A[mid - 1] if mid - 1 >=0 else float("-inf")
mid_right = A[mid + 1] if mid + 1 < len(A) else float(“inf”)

we should put either twice ("-inf") and the output will be twice 5 or
we should put twice (“inf”) and the output will be twice None.
Best regards
Miguel


Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers