编程语言
首页 > 编程语言> > python将字段转换成key=value字符串

python将字段转换成key=value字符串

作者:互联网

"""
将字典排序转换成键值对
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

标签:转换成,python,items,value,dictA,key,keyValue,键值
来源: https://www.cnblogs.com/zengyu0714/p/16410224.html