删除两个词典之间的常用条目 [英] Delete common entries between two dictionaries

查看:90
本文介绍了删除两个词典之间的常用条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个留言板上得到了很好的帮助。我想知道我是否可能会在这方面得到更多的帮助。


我正处于我有两个词典的地方,有关于一个

域名和该域名的频率。


既然我有两个,我想删除两个中的每个条目

有共同点,只留下字典中唯一的那些?


我说有一个名为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.

推荐答案

2003年11月24日星期一13:24:17 -0800,Amy G写道:
On Mon, 24 Nov 2003 13:24:17 -0800, Amy G wrote:
我在这个留言板上得到了很好的帮助。我想知道我是否可能在这方面得不到你的帮助。

我正处于有两个字典的地方,有一个域名和一个域名的信息该领域的频率。

现在我有两个,我想删除两个共同的一个条目,只留下那些独特的条目
字典?


如果套装适当地为你的数据建模,这对套装来说会很棒。

(有两套,这只是(s1-(s1& s)。 s2)))

说我有一个名为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?
This would be great for sets, if a set adequately models your data.
(with two sets, this would simply be (s1-(s1&s2)))
Say I have a dictionary called domains_black and another
domains_white...




你想要定义吗?按键或键(键,值)对等等?

对于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: http://dman13.dyndns.org/~dman/ jabber: DM ** @ dman13.dyn dns.org



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


" Amy G" <是******* @ cox.net>写道:
"Amy G" <am*******@cox.net> writes:
既然我有两个,我想从两个共同的条目中删除每个条目,只留下字典中唯一的条目吗?

说我有一个名为domains_black的词典
和另一个domains_white ...
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...




for domains_white():

如果domain_black中的k:

del domains_black [k]



for k in domains_white():
if k in domains_black:
del domains_black[k]


文章< 97 ********** **@dman13.dyndns.org>,

德里克''dman''哈德森< dm ** @ dman13.dyndns.org>写道:
In article <97************@dman13.dyndns.org>,
Derrick ''dman'' Hudson <dm**@dman13.dyndns.org> wrote:
如果一组充分模拟你的数据,这对集合来说会很棒。
(有两组,这只是(s1-(s1& s2)) ))
This would be great for sets, if a set adequately models your data.
(with two sets, this would simply be (s1-(s1&s2)))




你的意思是s1 - s2,不需要额外的& ;.


-

David Eppstein http://www.ics.uci.edu/ ~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


这篇关于删除两个词典之间的常用条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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