Python: Checking to which bin a value belongs
问题 I have a list of values and a list of bin edges. Now I need to check for all values to what bin they belong to. Is there a more pythonic way than iterating over the values and then over the bins and checking if the value belongs to the current bin, like: my_list = [3,2,56,4,32,4,7,88,4,3,4] bins = [0,20,40,60,80,100] for i in my_list: for j in range(len(bins)): if bins(j) < i < bins(j+1): DO SOMETHING This doesn't look very pretty to me. Thanks! 回答1: Probably too late, but for future