There is a way, but I wouldn't consider it as very robust. There is a subtle difference in the error messages:
a = [1,2,3]
b = [1,2,3]
a[2] = b[3]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-69-8e0d280b609d> in <module>()
2 b = [1,2,3]
3
----> 4 a[2] = b[3]
IndexError: list index out of range
But if the error is on the left hand side:
a[3] = b[2]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-68-9d66e07bc70d> in <module>()
2 b = [1,2,3]
3
----> 4 a[3] = b[2]
IndexError: list assignment index out of range
Note the 'assignment' in the message.
So, you could do something like:
a = [1,2,3]
b = [1,2,3]
try:
a[3] = b[2]
except IndexError as e:
message = e.args[0]
if 'assignment' in message:
print("Error on left hand side")
else:
print("Error on right hand side")
Output:
# Error on left hand side
Again, I wouldn't trust it too much, it would fail if the message changes in another version of Python.
I had a look at these parts of the source code, these different messages are really the only difference between the two errors.