• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tools.filter_unique函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pywikibot.tools.filter_unique函数的典型用法代码示例。如果您正苦于以下问题:Python filter_unique函数的具体用法?Python filter_unique怎么用?Python filter_unique使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了filter_unique函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_obj_id

 def test_obj_id(self):
     """Test filter_unique with objects using id as key, which fails."""
     # Two objects which may be equal do not necessary have the same id.
     deduped = set()
     deduper = tools.filter_unique(self.decs, container=deduped, key=id)
     self.assertEqual(len(deduped), 0)
     for _ in self.decs:
         self.assertEqual(id(next(deduper)), deduped.pop())
     self.assertRaises(StopIteration, next, deduper)
     # No. of Decimal with distinct ids != no. of Decimal with distinct value.
     deduper_ids = list(tools.filter_unique(self.decs, key=id))
     self.assertNotEqual(len(deduper_ids), len(set(deduper_ids)))
开发者ID:PersianWikipedia,项目名称:pywikibot-core,代码行数:12,代码来源:tools_tests.py


示例2: test_process_again

 def test_process_again(self):
     """Test filter_unique with an ignoring container."""
     deduped = ProcessAgainList()
     deduper = tools.filter_unique(self.ints, container=deduped)
     deduped_out = list(deduper)
     self.assertEqual(deduped_out, [1, 3, 2, 1, 1, 4])
     self.assertEqual(deduped, set([2, 4]))
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:7,代码来源:tools_tests.py


示例3: test_skip

 def test_skip(self):
     """Test filter_unique with a container that skips items."""
     deduped = SkipList()
     deduper = tools.filter_unique(self.ints, container=deduped)
     deduped_out = list(deduper)
     self.assertCountEqual(deduped, deduped_out)
     self.assertEqual(deduped, set([2, 4]))
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:7,代码来源:tools_tests.py


示例4: test_stop

    def test_stop(self):
        """Test filter_unique with an ignoring container."""
        deduped = ContainsStopList()
        deduped.stop_list = [2]
        deduper = tools.filter_unique(self.ints, container=deduped)
        deduped_out = list(deduper)
        self.assertCountEqual(deduped, deduped_out)
        self.assertEqual(deduped, set([1, 3]))

        # And it should not resume
        self.assertRaises(StopIteration, next, deduper)

        deduped = AddStopList()
        deduped.stop_list = [4]
        deduper = tools.filter_unique(self.ints, container=deduped)
        deduped_out = list(deduper)
        self.assertCountEqual(deduped, deduped_out)
        self.assertEqual(deduped, set([1, 2, 3]))

        # And it should not resume
        self.assertRaises(StopIteration, next, deduper)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:21,代码来源:tools_tests.py


示例5: test_for_resumable

 def test_for_resumable(self):
     """Test filter_unique is resumable after a for loop."""
     gen2 = tools.filter_unique(self.ints)
     deduped = []
     for item in gen2:
         deduped.append(item)
         if len(deduped) == 3:
             break
     self.assertEqual(deduped, [1, 3, 2])
     last = next(gen2)
     self.assertEqual(last, 4)
     self.assertRaises(StopIteration, next, gen2)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:12,代码来源:tools_tests.py


示例6: test_str_id

 def test_str_id(self):
     """Test str using id as key fails on Python 3."""
     # str in Python 3 behave like objects.
     deduped = set()
     deduper = tools.filter_unique(self.strs, container=deduped, key=id)
     self._test_dedup_str(deduped, deduper, id)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:6,代码来源:tools_tests.py


示例7: test_str_hash

 def test_str_hash(self):
     """Test filter_unique with str using hash as key."""
     deduped = set()
     deduper = tools.filter_unique(self.strs, container=deduped, key=hash)
     self._test_dedup_str(deduped, deduper, hash)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:5,代码来源:tools_tests.py


示例8: test_str

 def test_str(self):
     """Test filter_unique with str."""
     deduped = set()
     deduper = tools.filter_unique(self.strs, container=deduped)
     self._test_dedup_str(deduped, deduper)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:5,代码来源:tools_tests.py


示例9: test_obj_id

 def test_obj_id(self):
     """Test filter_unique with objects using id as key, which fails."""
     # Two objects which may be equal do not have the same id.
     deduped = set()
     deduper = tools.filter_unique(self.decs, container=deduped, key=id)
     self._test_dedup_int(deduped, deduper, id)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:6,代码来源:tools_tests.py


示例10: test_obj_hash

 def test_obj_hash(self):
     """Test filter_unique with objects using hash as key."""
     deduped = set()
     deduper = tools.filter_unique(self.decs, container=deduped, key=hash)
     self._test_dedup_int(deduped, deduper, hash)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:5,代码来源:tools_tests.py


示例11: test_obj

 def test_obj(self):
     """Test filter_unique with objects."""
     deduped = set()
     deduper = tools.filter_unique(self.decs, container=deduped)
     self._test_dedup_int(deduped, deduper)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:5,代码来源:tools_tests.py


示例12: test_int_id

 def test_int_id(self):
     """Test filter_unique with ints using id as key."""
     deduped = set()
     deduper = tools.filter_unique(self.ints, container=deduped, key=id)
     self._test_dedup_int(deduped, deduper, id)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:5,代码来源:tools_tests.py


示例13: test_OrderedDict

 def test_OrderedDict(self):
     """Test filter_unique with a OrderedDict."""
     deduped = tools.OrderedDict()
     deduper = tools.filter_unique(self.ints, container=deduped)
     self._test_dedup_int(deduped, deduper)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:5,代码来源:tools_tests.py


示例14: test_set

 def test_set(self):
     """Test filter_unique with a set."""
     deduped = set()
     deduper = tools.filter_unique(self.ints, container=deduped)
     self._test_dedup_int(deduped, deduper)
开发者ID:happy5214,项目名称:pywikibot-core,代码行数:5,代码来源:tools_tests.py



注:本文中的pywikibot.tools.filter_unique函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.first_lower函数代码示例发布时间:2022-05-26
下一篇:
Python textlib.TimeStripper类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap