Notice that the closed parameter is, by default, right, which means that the intervals are open on the left-end-point and closed on the right-end-point. That’s why 0 (which is the lowest of values in any interval) is not included; it is the left-end-point of the first interval.
Exactly! The variable name _ is used when you don’t care about the actual variable.
In this example we want to create a list with ten elements all of which are zero. To this end, it doesn’t really matter if we use i or not, both [0 for i in range(10)] and [0 for _ in range(10)] work, because the expression 0 doesn’t use the variable at all.
In these situations, by convention, we usually use _. Technically it is not necessary, it’s just a Python-community’s agreement to use _ when we don’t care about the variable.
@Bruno, why do we need to .loc here for the series within the for loop? I thought we could use the shorthand of dropping the .loc for referring to a single item from a series, but I run into an error when I drop it.
for value in points:
for interval in intervals:
if value in interval:
new_series**.loc**[interval] += 1
break