title: How do I sort the list by running thorough every element?
body: <p><a href="https://i.stack.imgur.com/Hzw72.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hzw72.png" alt="Expected algorithm" /></a>
  Based on the image, my code is supposed to run 'k' 12 times even though the list is already sorted at the 7th step. However, my code only ran it 6 times to achieve the sorted list. How can i make it run 12 times according to the image?</p>
  <p>Also, I have to count the number of steps required to sort 'k', so I used enumerate but the output were 0 0 0 1 1 2. I need it to give me the output 12 instead. Am i doing something wrong?</p>
  <pre><code>    def sorting_function(k):
          for index, i in enumerate(range(len(k))):
              for num in range(len(k) - 1):
                  if k[num] &gt; k[num+1]:
                      k[num], k[num+1] = k[num+1], k[num]
                      print(index)
  
      k = [4, 3, 2, 1]
      sorting_function(k)
      print(k)
  </code></pre>