a=['oc2P70Ph14EBiLrX3jI-c138f4tg','oc2P70Gt9duc-1Km4WE4FbxUsHpU','oc2P70MfrRM5lYRVI1d1fthWh3qM','oc2P70FqFlOXON3lQsbtntY2_0Sw',
'oc2P70DTCD3mzLrHVOAhyT0nWtZY']
怎么样创建多个字典形成这样的形式
{"algo_type": "XGB","scene_id": "child_purchase", "algo_version": "20210930", "bid": "wesure","request_id": "e24a15cf","user_id": "oc2P70Ph14EBiLrX3jI-c138f4tg" }
{"algo_type": "XGB","scene_id": "child_purchase", "algo_version": "20210930", "bid": "wesure","request_id": "e24a15cf","user_id": "oc2P70Gt9duc-1Km4WE4FbxUsHpU" }
{"algo_type": "XGB","scene_id": "child_purchase", "algo_version": "20210930", "bid": "wesure","request_id": "e24a15cf","user_id": "oc2P70MfrRM5lYRVI1d1fthWh3qM" }
{"algo_type": "XGB","scene_id": "child_purchase", "algo_version": "20210930", "bid": "wesure","request_id": "e24a15cf","user_id": "oc2P70FqFlOXON3lQsbtntY2_0Sw" }
{"algo_type": "XGB","scene_id": "child_purchase", "algo_version": "20210930", "bid": "wesure","request_id": "e24a15cf","user_id": "oc2P70DTCD3mzLrHVOAhyT0nWtZY" }

python 循环创建多个字典
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 缘emo 2021-12-04 17:15关注
a = ['oc2P70Ph14EBiLrX3jI-c138f4tg', 'oc2P70Gt9duc-1Km4WE4FbxUsHpU', 'oc2P70MfrRM5lYRVI1d1fthWh3qM', 'oc2P70FqFlOXON3lQsbtntY2_0Sw', 'oc2P70DTCD3mzLrHVOAhyT0nWtZY'] n = 1 for i in a: s = 'dic'.join(str(n)) s = {"algo_type": "XGB", "scene_id": "child_purchase", "algo_version": "20210930", "bid": "wesure", "request_id": "e24a15cf"} s["user_id"] = i n += 1 print(s)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报