I see similar questions asked for Java and PHP, but couldn't find a way to it in python3.
I have the following object:
object{
id
time
}
Assume that time is between 0-1000
I have created a list of instances of this object.
{['idA', 33], ['idB', 68], ['idC', 453], ['idD', 3], ...}
I have also have a list of bins:
bins = numpy.linspace(0, 1000, 100)
>>> array([ 0. , 10.1010101 , 20.2020202 , 30.3030303 ,
40.4040404 , 50.50505051, 60.60606061, 70.70707071,
80.80808081, 90.90909091, 101.01010101, 111.11111111,
121.21212121, 131.31313131, ... 989.8989899 , 1000. ])
My question: I want to put the objects in the list into bins based on the values given above. I can do this using a for loop.
But is there a easier/cleaner way that this can be done? Particularly I am looking for something like this that I found here:
# To sort the list in place...
ut.sort(key=lambda x: x.count, reverse=True)
# To return a new list, use the sorted() built-in function...
newlist = sorted(ut, key=lambda x: x.count, reverse=True)