qq_43601497 2021-12-04 16:57 采纳率: 80%
浏览 326
已结题

python 循环创建多个字典

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" }

  • 写回答

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)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月15日
  • 已采纳回答 3月7日
  • 创建了问题 12月4日

悬赏问题

  • ¥15 关于c++外部库文件宏的问题,求解
  • ¥15 office打开卡退(新电脑重装office系统后)
  • ¥300 FLUENT 火箭发动机燃烧EDC仿真
  • ¥15 【Hadoop 问题】Hadoop编译所遇问题hadoop-common: make failed with error code 2
  • ¥15 vb6.0+webbrowser无法加载某个网页求解
  • ¥15 RPA财务机器人采购付款流程
  • ¥15 计算机图形多边形及三次样条曲线绘制
  • ¥15 根据protues画的图用keil写程序
  • ¥200 如何使用postGis实现最短领规划?
  • ¥15 pyinstaller打包错误