问题描述
我在这个留言板上得到了很好的帮助。我想知道我是否可能会在这方面得到更多的帮助。
我正处于我有两个词典的地方,有关于一个
域名和该域名的频率。
既然我有两个,我想删除两个中的每个条目
有共同点,只留下字典中唯一的那些?
我说有一个名为domains_black的词典
和另一个domains_white。 ..
感谢您的帮助。
I have received such good help on this message board. I wonder if I might
not get a little more help from you on this.
I am at the point where I have two dictionaries, with information of a
domain and a frequency of that domain.
Now that I have the two, I want to delete each entry from one that the two
have in common, leaving only those that are unique to the dictionary?
Say I have a dictionary called domains_black
and another domains_white...
Thanks for the help.
推荐答案
你想要定义吗?按键或键(键,值)对等等?
对于domains_white.keys()中的键,
:
如果在domains_black中键入
:del domains_black [key ]
表示domains_white.keys()中的键:
如果在domains_black和domains_white [key]中键入== domains_black [key]:
del domains_black [key]
-D
-
嘲笑指令的人将会支付它,
但尊重命令的人会得到回报。
箴言13:13
www: jabber:
Did you want to define equality by key or by (key, value) pair?
for key in domains_white.keys() :
if key in domains_black: del domains_black[key]
for key in domains_white.keys() :
if key in domains_black and domains_white[key] == domains_black[key] :
del domains_black[key]
-D
--
He who scorns instruction will pay for it,
but he who respects a command is rewarded.
Proverbs 13:13
www: http://dman13.dyndns.org/~dman/ jabber: dm**@dman13.dyndns.org
for domains_white():
如果domain_black中的k:
del domains_black [k]
for k in domains_white():
if k in domains_black:
del domains_black[k]
你的意思是s1 - s2,不需要额外的& ;.
-
David Eppstein
大学加州,欧文,信息学院和计算机科学
You mean s1 - s2, no need for that extra &.
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
这篇关于删除两个词典之间的常用条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!