2 ms·
Bisect is nice, but it's not the fastest option. If binning data, discretize it and then use a dict lookup - `grades_to_letters[grade//10]`, for example. For
by zhd 6y ago
Bisect is nice, but it's not the fastest option.
If binning data, discretize it and then use a dict lookup - `grades_to_letters[grade//10]`, for example.
For insort, and indeed anything with sorted collections, just use the http://www.grantjenks.com/docs/sortedcontainers/ http://www.grantjenks.com/docs/sortedcontainers/ module. Inserting an element is worst-case sublinear time, and also faster than C-extensions. It's one of the very few data-structure libraries I use regularly.