-1

I have simple list of data which looks like:

_MOBILE_CATEGORIES = {
    100152307: 424,
    100152547: 55,
    100152385: 66,
    100152395: 13,
    100152405: 130,
    100152365: 50,
    100152290: 218,
    100152446: 26
}

When I print it I get:

{100152385: 66, 100152290: 218, 100152307: 424, 100152405: 130, 100152547: 55, 100152395: 13, 100152365: 50, 100152446: 26}

As you cant see first goes 100152385: 66 which in list is third.

_MOBILE_CATEGORIES = {
    '100152307': 424,
    '100152547': 55,
    '100152385': 66,
    '100152395': 13,
    '100152405': 130,
    '100152365': 50,
    '100152290': 218,
    '100152446': 26
}

If I define keys as string I get other order like this:

{'100152290': 218, '100152307': 424, '100152385': 66, '100152446': 26, '100152405': 130, '100152395': 13, '100152365': 50, '100152547': 55}

So I need to define dict so that it would be in the order I need?

Kiril
  • 331
  • 1
  • 5

1 Answers1

2

Python dicts are unordered by their own nature. To get the feature you want use an OrderedDict.

Bonifacio2
  • 3,405
  • 6
  • 34
  • 54