#标注 sorted()函数默认按ascii排序
# coding=utf-8
import urllib
dict_param={"test":"FFFF","Aadmin":"33FFFHtest","key":"values"}
target=sorted(dict_param.items(),key=lambda x:x[1],reverse=False)#字典按照value ascii排序,lambda x :x[0]按照键key ascii排序 ,数字大写小写顺序
print(target)
res= urllib.parse.urlencode(target)
print(res)
或者自己重写个拼接方法很简单:
result=""
for k,v in dict(target).items():
result +=k+"="+v
print(result)
[('Aadmin', '33FFFHtest'), ('test', 'FFFF'), ('key', 'values')]
Aadmin=33FFFHtesttest=FFFFkey=values