Python教程

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将字段转换成key=value字符串的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!