I am quite new to Python (I'm more used to C, C#). I am trying to learn and I want to try to do things as 'Pythonic' as possible.
I want to iterate over intervals and then do something based on whether or not a number is in the interval. I know I can create my intervals using numpy.arrange (or some other array defintion) and then iterate over the bins like so
ibins = numpy.arange(start = 19, stop = 67, step = 2)
a = 50
for idx, val in enumerate(ibins) :
if idx > 0:
if ibins[idx - 1] <= a < ibins[idx] :
#do something more meaningfull
print('Hello')
However, reading on various posts it is my understanding that using the index to access the bin elements is considered 'bad form' in Python.
What I would like to do is something more like this
for ibin in ibins
if a is in ibin #somehow determine if a is in the bin
print('Hello')
Is there a reasonable, short way to achieve this? Or is my first suggestion the best way to go.
I do not want to create custom interval-objects or things of that sort.