How do I find the duplicates in a list and create another list with them?

To remove duplicates use set(a). To print duplicates, something like: Note that Counter is not particularly efficient (timings) and probably overkill here. set will perform better. This code computes a list of unique elements in the source order: or, more concisely: I don’t recommend the latter style, because it is not obvious what not seen.add(x) is doing (the set add() method always returns None, hence … Read more

Fastest way to duplicate an array in JavaScript – slice vs. ‘for’ loop

There are at least 6 (!) ways to clone an array: loop slice Array.from() concat spread operator (FASTEST) map A.map(function(e){return e;}); There has been a huuuge BENCHMARKS thread, providing following information: for blink browsers slice() is the fastest method, concat() is a bit slower, and while loop is 2.4x slower. for other browsers while loop is the fastest method, since those browsers don’t have internal optimizations for slice and concat. This remains … Read more

How do I find the duplicates in a list and create another list with them?

To remove duplicates use set(a). To print duplicates, something like: Note that Counter is not particularly efficient (timings) and probably overkill here. set will perform better. This code computes a list of unique elements in the source order: or, more concisely: I don’t recommend the latter style, because it is not obvious what not seen.add(x) is doing (the set add() method always returns None, hence … Read more

Finding duplicate values in a SQL table

Simply group on both of the columns. Note: the older ANSI standard is to have all non-aggregated columns in the GROUP BY but this has changed with the idea of “functional dependency”: In relational database theory, a functional dependency is a constraint between two sets of attributes in a relation from a database. In other words, … Read more