0

I was trying to create dictionary but the key are always re-arranged. I wanted the key to be arranged in appropriate order. Is it possible in python?

#!/bin/python

my_val = ["vel", "acc", "force"]

my_dict=dict()
for v in my_val:
  my_dict[v] = []

for l in my_val:
  print("l = ", l) 

print("dict re-arranges")
for key in my_dict:
  print("key = ", key)
l =  vel
l =  acc
l =  force
dict re-arranges
key =  force
key =  acc
key =  vel
mato
  • 503
  • 8
  • 18
  • 7
    Use Python 3.7+, or use a `collections.OrderedDict` in older Python versions. – wim Sep 23 '19 at 22:33
  • 1
    Relevant SO thread: https://stackoverflow.com/questions/39980323/are-dictionaries-ordered-in-python-3-6 – R. Arctor Sep 23 '19 at 22:46

0 Answers0