list - Create Python Dictionary -


a_lst = list() b_lst = list() tmp = list() c_dct = dict() while true:    = raw_input("a=")    a_lst.append(a)    b = raw_input("b=")    b_lst.append(b)    if == "end":       break a_lst.remove('end') print a_lst print b_lst   in range(len(a_lst)):    c_dct[a_lst[i]] = b_lst[i]    print c_dct 

in code, combine 2 lists create dictionary. in result, dictionary not same position input. example,

c_dct = {'q': 'w', 'e': 'r', 'o': 'p', '1': '2', '3': '4', '5': '6', 't': 'y', '7': '8', '9': '0', 'u': 'i'} 

instead of

c_dct =  {'1': '2', '3': '4', '5': '6','7': '8', '9': '0','q': 'w', 'e': 'r','t': 'y','u': 'i','o': 'p'} 

what going on code? how slove problem? thank much!

dictionaries not maintain order default. if need ordered dictionary, can use following:

from collections import ordereddict 

take @ documentation


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -