est est - 4 months ago 4x
Python Question

Most pythonic way to find number index in a sorted list?

a = 132

b = [0, 10, 30, 60, 100, 150, 210, 280, 340, 480, 530]

I want to know that
should be in the 6th position in ordered list

What's the most pythonic way to do so?


Use bisect. It's not the most beautiful API, but it's exactly what you need.

You'll want to use bisect.bisect, which returns exactly what you want.