I have a list of lists that I want to re-order:
qvalues = [[0.1, 0.3, 0.6],[0.7, 0.1, 0.2],[0.3, 0.4, 0.3],[0.1, 0.3, 0.6],[0.1, 0.3, 0.6],[0.1, 0.3, 0.6]]
I know how to reorder this list if I have a list with the order I want (example here). The tricky part is getting this order.
What I have is this:
locations = [(['Loc1','Loc1'], 3), (['Loc2'], 1), (['Loc3', 'Loc3', 'Loc3'], 2)]
This is a list of tuples, where the first element of each tuple is a list with the location name, repeated for each individual in that location, and the second element is the order these individuals are in on the qvalues
list (qvalues[0]
is 'Loc2'
, qvalues[1:4]
are 'Loc3'
and qvalues[4:6]
are 'Loc1'
.
What I want is to change the order of the lists in qvalues
to the order they show up in locations
: First 'Loc1'
, then 'Loc2'
and finally 'Loc3'
.
This is just a small example, my real dataset has hundreds of individuals and 17 locations.
Thanks in advance for any help you may provide.