Python: Listing the duplicates in a list
<p>I am fairly new to Python and I am interested in listing duplicates within a list. I know how to remove the duplicates ( <strong>set()</strong> ) within a list and how to list the duplicates within a list by using <strong>collections.Counter</strong>; however, for the project that I am working on this wouldn't be the most efficient method to use since the run time would be <strong>n(n-1)/2 --> O(n^2)</strong> and n is anywhere from 5k-50k+ string values.</p>

<p>So, my idea is that since python lists are linked data structures and are assigned to the memory when created that I begin counting duplicates from the very beginning of the creation of the lists.</p>

<ol>
<li>List is created and the first index value is the word 'dog'</li>
<li>Second index value is the word 'cat'</li>
<li>Now, it would check if the second index is equal to the first index, if it is then append to another list called Duplicates.</li>
<li>Third index value is assigned 'dog', and the third index would check if it is equal to 'cat' then 'dog'; since it matches the first index, it is appended to Duplicates.</li>
<li>Fourth index is assigned 'dog', but it would check the third index only, and not the second and first, because now you can assume that since the third and second are not duplicates that the fourth does not need to check before, and since the third/first are equal, the search stops at the third index.</li>
</ol>

<p>My project gives me these values and append it to a list, so I would want to implement that above algorithm because I don't care how many duplicates there are, I just want to know if there are duplicates.</p>

<p>I can't think of how to write the code, but I figured the basic structure of it, but I might be completely off (using random numgen for easier use):</p>

<pre><code>for x in xrange(0,10):
    list1.append(x)
    for rev, y in enumerate(reversed(list1)):
        while x is not list1(y):
            cond()
            if ???
</code></pre>
