sample_devs = []
for i in range(5000):
sample = houses['SalePrice'].sample(10, random_state=i)
st_dev = standard_deviation(sample)
sample_devs.append(st_dev)
plt.hist(sample_devs)
plt.axvline(standard_deviation(houses['SalePrice']))
So I am getting a weird error that I don’t think is an issue with my code as I just checked the answer to make sure I was not crazy. I think this is a bug. The error I get is:
TypeErrorTraceback (most recent call last)
<ipython-input-1-b7fdbfeb43e5> in <module>()
16
17
---> 18 for i in range(5000):
19 sample = houses['SalePrice'].sample(10, random_state=i)
20 st_dev = standard_deviation(sample)
<ipython-input-1-d7b275ef9597> in range(array)
3
4 def range(array):
----> 5 variability = max(array) - min(array)
6 return variability
7
TypeError: 'int' object is not iterable
Can someone confirm that this is a bug or point out the error I am overlooking?
Many Thanks!
Edit I am also seeing this same error appear on 308-9 Bassel’s Correction. Same error and everything.
So when you try to run for i in range(5000), it passes 5000to your range function, not to the built-in one. When it tries to compute max(5000), it yields an error because max expects an iterable and integers aren’t iterables.
It’s possibly you created this function in a previous screen in this mission and it propagated to the following screens.
Solution
So how do you fix this? Three ways come to mind:
You don’t do anything, you just open the link and try again. I think this will work because the code runner will have been reset and your definition of range won’t be in memory anymore (I hope).
You call the built-in function directly:
for i in __builtins__.range(5000):
sample = houses['SalePrice'].sample(100, random_state = i)
st_dev = standard_deviation(sample)
st_devs.append(st_dev)
You assign the built-in range function to range. Two ways to do this follow below.
Running del range will delete your function’s definition and make range default to the built-in function.
Running range = __builtins__.range will overwrite your function’s definition with that of the built-in function.
What a lapse in good judgement overwriting the built-in function. In my mind, it was just for the screens that involved us using our own functions. Lesson learned! It appears the code runner refreshed and my oops is corrected. Thanks!