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
Post a Comment