0

I want to extract the dictionary keys, preserving their order (CTY, LC, DIV). When I perform a list comprehension, it is automatically ordering them.

[dictionary with keys

columns = [key for key in dict_columns.keys()]

[generated list

Any suggestions?

sentence
  • 8,213
  • 4
  • 31
  • 40
tyasia16
  • 51
  • 1
  • 6

1 Answers1

0

consider using an OrderedDict to preserve the order of keys in your dict

https://docs.python.org/3.7/library/collections.html#collections.OrderedDict

Jack Hamby
  • 198
  • 1
  • 10