Mar-13-2019, 07:46 PM
That will behave *almost* the same unless you're modifying M somewhere. Otherwise, you're just replacing x >= 10 with x >= M[i], which will always be M[0] or M[1]. You still have a huge potential for an index error.
If
What are you trying to accomplish?
If
[L[i] for i in range(2) if x >= M[i] and x < M[i+1]]creates an empty list, then there won't be an item to index at [0].
What are you trying to accomplish?