""" 将字典排序转换成键值对 dictA={"a":"1","c":"3","e":"5","d":"4","b":"2"} """ dictA = {"a": "1", "c": "3", "e": "5", "d": "4", "b": "2"} dictA = dict(sorted(dictA.items(),key = lambda x:x[0])) keyValue = "&".join(['{}={}'.format(*i) for i in dictA.items()]) print(keyValue)
运行结果:
a=1&b=2&c=3&d=4&e=5