usr bin env python from django utils datastructures import SortedDict

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
from django.utils.datastructures import SortedDict
DATA = {
1: (2, 3),
2: (4,),
3: (4,),
}
def perform():
d = SortedDict()
for k, deps in DATA.items():
latestdep = 0
if k in d:
raise Exception("WTF?!")
for dep in deps:
if dep in deps:
try:
latestdep = d.keyOrder.index(dep)
except ValueError:
pass
d.insert(latestdep, k, deps)
return d
if __name__ == '__main__':
print perform()