I have a list port_ids, which are in right order. Based on that I fetch the value from a file and store it in a dictionary. But the stored values in the dictionary are not aligned with the original list. This is my code:
import os
os.chdir('/var/lib/docker/volumes/kolla_logs/_data/openvswitch/')
port_ids=['qvoee855b93-ba', 'qvo9aa3a7d8-64', 'qvo2fc6e482-aa', 'qvo6a27cf40-8f']
def port_numb(text):
try:
with open('ovs-vswitchd.log') as f:
for line in f:
if line.find(text) != -1:
return line[97:100]
except Exception as ex:
print('Failed to open file {}'.format(ex))
ovs_port_numb = list(map(port_numb, port_ids))
d = dict(zip(port_ids, ovs_port_numb))
print d
OUTPUT: {'qvoee855b93-ba': '174', 'qvo2fc6e482-aa': '176', 'qvo6a27cf40-8f': '177', 'qvo9aa3a7d8-64': '175'}
I want the keys of the dictionary to be in the same order like in the list (port_ids).