美文网首页
习题9:删除多余的数

习题9:删除多余的数

作者: 今年说话算话 | 来源:发表于2017-02-22 00:21 被阅读0次

Delete occurrences of an element if it occurs more than n times

当序列中某元素出现次数的超出n次,删除
def delete_nth(l, max_e):
    r = []
    for i in l:
        if r.count(i) < max_e:
            r.append(i)
    return r

相关文章

网友评论

      本文标题:习题9:删除多余的数

      本文链接:https://www.haomeiwen.com/subject/zndpwttx.html