[Tutor] Sort a list following the order of other list

Jonas Melian jonasmg at SoftHome.net
Mon Aug 22 20:19:25 CEST 2005


best = [ [1024, 768], [800, 600], [640, 480] ]  (it's larger)

modes = [
(24, [1280, 1024]),
(24, [1024, 768]),
(24, [640, 480]),
(16, [1600, 1200]),
(16, [1280, 1024]),
(15, [320, 200]),
]

I want to create a list with ALL elements of 'modes', but following the 
order of list 'best' (if exist the number). At the end the rest of 
numbers in modes, are added too. And all this for each modes[0] (24, 16, 
15, ...)

For a simple list is easy:
a = [123, 45, 98, 2, 12];  b=[12, 35, 45, 2]
[y for y in b if y in a] + [x for x in a if x not in b]

Help please, that i'm going crazy
v 2.3.5

Thanks in advance


More information about the Tutor mailing list