You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于给定变量创建动态键:构建Bitbucket分支子分支映射字典

分支与子分支的字典映射实现

给定两个列表,其中listOfRepos存储分支路径,listOfChildBranches存储对应分支的子分支列表,需要生成以分支路径为键、子分支列表为值的字典,并输出指定格式的结果。

给定变量

listOfRepos = ['repo/association/branch/master','repo/publish/branch/master']
listOfChildBranches = [["childBranch1","childBranch2","childBranch3"], 
                       ["working1","demo2","rebased3"]]

实现代码

利用Python的zip()函数将两个列表按索引配对,直接转换为字典即可满足需求:

# 生成目标字典
branch_map = dict(zip(listOfRepos, listOfChildBranches))

# 按期望格式输出结果
for branch_path, child_branches in branch_map.items():
    print(f"{branch_path}={child_branches}")

输出结果

repo/association/branch/master=['childBranch1', 'childBranch2', 'childBranch3']
repo/publish/branch/master=['working1', 'demo2', 'rebased3']

内容的提问来源于stack exchange,提问作者JerryBurnard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 03:52:02