作者:迷迷糊糊的Nancy | 来源:互联网 | 2023-10-16 01:07
test=[
{"url":"/order.html","code":"post"},
{"url":"/order.html","code":"get"},
{"url":"/order.html","code":"put"},
{"url":"/order.html","code":"delete"},
{"url":"/index.html","code":"post"},
{"url":"/index.html","code":"get"},
{"url":"/index.html","code":"put"},
{"url":"/login.html","code":"put"},
{"url":"/login.html","code":"get"},
{"url":"/login.html","code":"post"},
]
handler={}
for item in test:
if item['url'] in handler:
handler[item["url"]].append(item["code"])
else:
handler[item["url"]] = [item["code"]] #用列表方式接收
print(handler)
#{'/order.html': ['post', 'get', 'put', 'delete'], '/index.html': ['post', 'get', 'put'], '/login.html': ['put', 'get', 'post']}