python: sorting
Posted
by nabizan
on Stack Overflow
See other posts from Stack Overflow
or by nabizan
Published on 2010-04-13T14:20:10Z
Indexed on
2010/04/13
14:22 UTC
Read the original article
Hit count: 387
hi im doing a loop so i could get dict of data, but since its a dict it's sorting alphabetical and not as i push it trought the loop ...
is it possible to somehow turn off alphabetical sorting?
here is how do i do that
data = {}
for item in container:
data[item] = {}
...
for key, val in item_container.iteritems():
...
data[item][key] = val
whitch give me something like this
data = {
A : { K1 : V1, K2 : V2, K3 : V3 },
B : { K1 : V1, K2 : V2, K3 : V3 },
C : { K1 : V1, K2 : V2, K3 : V3 }
}
and i want it to be as i was going throught the loop, e.g.
data = {
B : {K2 : V2, K3 : V3, K1 : V1},
A : {K1 : V1, K2 : V2, K3 : V3},
C : {K3 : V3, K1 : V1, K2 : V2}
}
© Stack Overflow or respective owner