简体   繁体   English

如何从字典中删除两个重复项?

[英]How to Remove Both Duplicates from a Dictionary?

I'm writing a reducer for a MapReduce program that is supposed to read two csv files: all-bills.csv and open-bills.csv . 我正在为MapReduce程序编写一个reducer,它应该读取两个csv文件: all-bills.csvopen-bills.csv What I want to do is remove values in open-bills from all bills so that I can get all the paid bills. 我想要做的是从所有账单中删除未结账单中的值,以便我可以获得所有已付账单。

What I have done is to add all the entries into a dictionary in my reducer. 我所做的是将所有条目添加到我的reducer中的字典中。 How do I remove the entries that occur twice or more than that so that I'm left with just the paid bills in my dictionary? 如何删除出现两次或更多次的条目,以便我只留下字典中的付费账单?

尝试这个:

{k: v for k, v in all_bills.items() if k not in open_bills}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM