帮助添加字典值 [英] help with addition of dictionary values

查看:92
本文介绍了帮助添加字典值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i想添加我的两个矩阵,使用__add__




i would like to add my two matrices, using __add__


展开 | 选择 | Wrap | 行号

推荐答案

使用字典方法,items()。像这样:
Use the dictionary method, items(). Like this:
展开 | 选择 | Wrap | 行号



使用字典方法,项目。像这样:
Use the dictionary method, items. Like this:
展开 | 选择 | Wrap | 行号



for this loop什么是 value 意味着什么?我如何使用__setitem__中设置的那个?得到(键,0)给了我在__setitem__中设置的值吗?


抱歉,如果我听起来令人困惑,但说实话,我对传递元组感到困惑,我想知道使用该方法后每个值的确切位置。使用__init__方法我已经很好了,我只是混淆了设置它们后的值会发生什么


表示键,dd_1.items()中的值:

... dd_res [key] = dd_2.get(key,0)+ value
for this loop what does value means here? how can i use the one that i have set in __setitem__? does get(key, 0) gives me the value that i have set in __setitem__?

sorry if i sound confusing, but honestly i''m confused with the passing of tuples, i want to know exactly where does each value goes after using the method. am already fine with __init__ method, i''m just confused what happens to the values after setting them

for key, value in dd_1.items():
... dd_res[key] = dd_2.get(key, 0) + value



好​​的。你的班级很顺利。在线帮助可以更好地解释这些事情(无论如何更简洁):

OK. Your class is coming along nicely. The on-line help can probably explain these things better that I can (more succinctly, anyway):

展开 | 选择 | Wrap | 行号


这篇关于帮助添加字典值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆