返回序列中的重复项
我能想到的最好的办法是:
(defn dups [seq]
(map (fn [[id freq]] id)
(filter (fn [[id freq]] (> freq 1))
(frequencies seq))))
有更简洁的方法吗?
The best I could come up with was:
(defn dups [seq]
(map (fn [[id freq]] id)
(filter (fn [[id freq]] (> freq 1))
(frequencies seq))))
Is there a more concise way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用列表理解:
Use a list comprehension:
如果您想根据列表中项目的某些属性查找重复项(即,它是映射列表或记录/java 对象列表)
输出:
如果您有一个 java 对象列表并且想要查找所有名字重复的人:
If you'd like to find duplicates based off some property of the items in the list (i.e. it's a list of maps or a list of records/java objects)
outputs:
If you have a list of java objects and you want to find all the ones with duplicate first names:
最小过滤器和频率 oneliner 可以完成这项工作:
但是它在大数据上表现不佳。您必须通过说以下内容来帮助编译器:
Minimal filter and frequencies oneliner that does the job:
However it performs poorly on large data. You will have to help the compiler by saying:
some
是完美的函数。但是,它基本上与列表理解相同。
some
is the perfect function for this.However, it basically does the same as the list comprehension.