Append duplicate items at the end of list whithout changing the order
<p>I am new to python and was trying to Append duplicate items at the end of list whithout changing the order</p>

<pre><code>testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56]

def duplicate(alist):
    p = len(alist)
    duplicate = False
    for i in range(0, p):
        for j in range (i + 1, p):
            if alist[i] == alist[j]:
                b = alist.index(alist[j])
                a = alist.pop(b)
                alist.append(a)
                p -= 1
                duplicate = True

    print alist

if duplicate == False:
    print "No duplicate item found"

duplicate(testlist)
</code></pre>

<p>OUTPUT : <code>[32, 8, 1, 17, 5, 2, 42, 13, 56, 1, 2]</code></p>

<p>DESIRED OUTPUT : <code>[1, 2, 32, 8, 17, 5, 42, 13, 56, 1, 2]</code></p>

<p>Any help what wrong I am doing here</p>

<p>I solved it this way.  I also made some changes to make the code a bit more Pythonic.</p>

<pre><code>test_list = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56]

def duplicate(a_list):
    list_length = len(a_list)
    duplicate = False
    checked = []
    for i in range(list_length):
        if a_list.count(a_list[i]) &gt; 1:
            if a_list[i] not in checked:
                duplicate = True
                a_list.append(a_list[i])
                checked.append(a_list[i])
    if duplicate == False:
        print("No duplicate item found")
        return None
    return a_list

print(duplicate(test_list))
</code></pre>

python python-2.7 scripting