Programmers learn & share
0 votes

Problem :

Facing following python dictonary issue.
the elements in a dictionary are stored in ascending order, by the keys of the key-value pairs.
by (6.9k points)   | 187 views

1 Answer

0 votes

Solution :

You should use OrderedDict (it requires Python 2.7 or higher).

Also please note that OrderedDict({'a': 1, 'b':2, 'c':3}) will not work since the dict you have create with {...} has already forgotten the order of the elements. So you should use OrderedDict([('a', 1), ('b', 2), ('c', 3)]).

If you follow above approach your issue will be resolved.

by (36.1k points)  
2,204 questions
2,608 answers
241 users