jeudi 26 février 2015

Combine and sort lists, when order within original lists conserved

Say I have several datasets which I'm trying to combine and then sort by a certain category, but the order of the original lists needs to be conserved. For instance I have the following data sets:



[Event, variable X]

List A -- List B -- List C

[1A, 5] -- [1B, 2] -- [1C, 20]

[2A, 6] -- [2B, 4] -- [2C, 10]

[3A, 2] -- [3B, 12] -- [3C, 14]


I want to combine all the sets and see how they rank overall in order of X, which would be simple enough, but the order from their original list needs to be conserved (e.g. 3C can only happen after 2C). So the final list would look like:



1. [1B, 2]
2. [2B, 4]
3. [1A, 6]
4. [2A, 5]
5. [3A, 2]
6. [3B, 12]
7. [1C, 20]
8. [2C, 10]
9. [3C, 14]


So even though X in 3A is equivalent to 1B and lower than 2B, it can only be listed after all previous "A" events, which themselves cannot be listed until they exceed 2B


Aucun commentaire:

Enregistrer un commentaire