元组用法

例如,我们有一个电子邮件地址的集合(haystack),还要维护一个较小的电子邮件地址集合(needles),然后求出 needles 中有多少地址同时也出现在了 heystack 里。借助集合操作,我们只需要一行代码就可以了
needles 的元素在 haystack 里出现的次数,两个变量都是 set 类型
found = len(needles & haystack)
found = 0
for n in needles:
    if n in haystack:
        found += 1    

 

posted @ 2019-09-27 15:13  顽强的allin  阅读(204)  评论(0编辑  收藏  举报