I need a good way to ask for an array/matrix value, but reporting a default (0) value for out-of-bound index:
b[2][4] should return 0 if the 2nd index length is 3, and
b[-1][2] also
I checked this:
Getting a default value on index out of range in Python, but it seems to me that it would not work for negative indices - since python always add the array length to them (true?)
I was thinking along the line of overloading __getitem__
, but I just came to python 1 month ago, and I'm not so skilled...
any help appreciated!
alessandro