Is that Insertionsort?
<p>I really need your help, I am learning sorting-algorithms and i tried to make an Insertionsort-Algorithm. So could you please tell me whether this is an Insertionsort-Algorithm or not?</p>

<pre><code>def insertsort(l):
    for k in range(len(l)):
        for i in range(1,len(l)):
            if l[i]&lt;l[i-1]:
                while l[i]&lt;l[i-1]:
                    l.insert(i-1,l.pop(i))
    return l
</code></pre>

<p>I do not think so. You used two nested <strong>for</strong> loops and a <strong>while</strong>. In the pseudocode provided by @dreadedHarvester and the implementation provided in <a href="https://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#Python" rel="nofollow">RosettaCode</a> just one <strong>for</strong> loop and one <strong>while</strong> are used. </p>

<pre><code>def insertion_sort(l):
    for i in xrange(1, len(l)):
        j = i-1 
        key = l[i]
        while (l[j] &gt; key) and (j &gt;= 0):
           l[j+1] = l[j]
           j -= 1
        l[j+1] = key
</code></pre>

python algorithm sorting