针对数据:
hellow = {'0': {'title': '1', 'price': '166.00', 'image': 'http', 'link': 'http'}, '1': {'title': '2', 'price': '155.00', 'image': 'http', 'link': '//item.jd.com/4295237.html', 'name': '京东'}}
python3.7首先新版本需要用到是items
dict.items() 以列表返回可遍历的(键, 值) 元组数组 |
关键代码:
dict1 = sorted(hellow.items(),key=lambda item:(float(item[1]["price"])),reverse=False)//升序
dict1 = hellow = { '1': {'title': '2', 'price': '155.00', 'image': 'http', 'link': '//item.jd.com/4295237.html', 'name': '京东'},'0': {'title': '1', 'price': '166.00', 'image': 'http', 'link': 'http'}}
后台返回json数据由于浏览器会根据键值来排输出,所以传回时候需要注意键值的排序修改:
关键代码:
i=0
for k in dict2.keys():
t1[str(i)] = dict2[k]
i += 1
dict.keys()
以列表返回一个字典所有的键