-
Couldn't load subscription status.
- Fork 2.4k
Open
Description
I'm not exactly sure this is an issue but I'm going through your Udemy course right now (great course by the way!) and I was wondering about this part.
Dynamic Array Exercise.ipynb
def __getitem__(self, k):
"""
Return element at index k
"""
if not 0 <= k < self.n:
return IndexError('K is out of bounds!') # Check it k index is in bounds of array
return self.A[k] #Retrieve from array at index kIs there a particular reason why you use return IndexError instead of raise IndexError? I've searched a bit on the internet but cannot find a similar example. I'm only familiar with using raise IndexError and this is the first time I've seen an error returned like that.
Thanks!
EDIT:
Just noticed a potential typo in your code as I was re-reading my comment.
# Check it k index
^^
# if ?
Metadata
Metadata
Assignees
Labels
No labels