Python中文
首页
教程
问答
标签
搜索
登录
注册
将一个字典中的第二个值与另一个字典中的所有值相加
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有两个字典,有相同的键,但值不同。我想用dictionary1的所有值和dictionary2的第二个值做一个新的dictionary。你知道吗</p> <pre><code>input: dic1 = { 'ENST1' : [ 33, 55, 66, 77 ], 'ENST2' : [ 55, 32, 45 ] } dic2 = { 'ENST1' : [ 'abc', 100, 200 ], 'ENST2' : [ 'cdg', 200, 300 ] } output: dic3 = { 'ENST1' : [ 133, 155, 166, 177 ] , [ 'ENST2' : 255, 232, 245 ] } </code></pre> <p>我使用的是python3.6。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>此版本也适用于:</p> <pre><code>dic3 = {} for (k,v), (k2,v2) in zip(dic1.items(), dic2.items()): dic3[k] = [x+y for x, y in zip(v, v2)] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
8 回答
如何在python中从数据帧列表中删除引号
7 回答
如何在python中从数据帧创建列表
4 回答
如何在Python中从数据帧创建嵌套的JSON
3 回答
如何在Python中从数据帧显示wordcloud
4 回答
如何在Python中从数据帧的时间戳中删除字符
5 回答
如何在Python中从数据帧绘制简单绘图?
5 回答
如何在python中从数据帧行提取具有特定长度的范围?
1 回答
如何在python中从数据帧设置dict中的值
9 回答
如何在Python中从数据库中获得一个结果
1 回答
如何在python中从数据框中绘制分类条形图
3 回答
如何在Python中从数据框中选择特定细节?
3 回答
如何在python中从数据集中删除unicode
7 回答
如何在python中从数据集中删除某些数值?
10 回答
如何在python中从数据集中选择行
5 回答
如何在Python中从数组中删除元素
1 回答
如何在python中从数组中删除单个倒逗号?
8 回答
如何在python中从数组中删除对象?
7 回答
如何在python中从数组中删除引号
9 回答
如何在python中从数组中删除所有最小值
3 回答