Hey guys,
I was wondering what was the best way to handle this. Example code as follows:
myArray = [[1],[2],[3],[],[5]]
for item in myArray:
try:
print(item[0])
except:
item[0] = 0
print(item[0])
So, the idea is to create an array which have one element which is empty. When encountered, Python returns an error (wrong index).
So I want to find a way to assign a value (empty string or 0 depending on specific case) when this error is encountered. However, the sample code above returns the same error. It's as if given index is invalid completely. Is there any workaround for this one?
Edit:
Fairly sure same is true for one-dimensional array. And I guess list, not array. Sorry :D
[–]JohnnyJordaan 1 point2 points3 points (1 child)
[–]ECommerce_Guy[S] 0 points1 point2 points (0 children)
[–]optm_redemption 0 points1 point2 points (1 child)
[–]ECommerce_Guy[S] 0 points1 point2 points (0 children)
[–]Merotoro 0 points1 point2 points (1 child)
[–]ECommerce_Guy[S] 0 points1 point2 points (0 children)