title: IndexError: list index out of range with a while loop
body: <p>I've been trying to fix this but the same error message came up every time:</p>
  
  <blockquote>
    <p>while number_list[i] &lt;= number_list[j]:</p>
    
    <p>IndexError: list index out of range</p>
  </blockquote>
  
  <p>I've searched for the same type of bug, but not very similar cases found.</p>
  
  <p>Here it is the head program (orders the numbers of my list, from the little one to the bigger):</p>
  
  <pre><code>    number_list=[]
  
  list_lenght=int(input("List lenght: "))
  
  while len(number_list)&lt;list_lenght:
      item=input("Enter new item to the list:")
      number_list.append(item)
      print(number_list)
  
  print("That's your number list: ",number_list)
  
  number_list_final=[]
  
  def order_number_list(number_list):
      i=0
      j=1
      while (j)&lt;=(len(number_list)-1):
          while number_list[i]&lt;=number_list[j]:
              j=j+1
          i=j
          j=i+1
      final_item=number_list[i]
      number_list_final.append(final_item)`
      del number_list[i] 
      order_number_list(number_list)
  
  order_number_list(number_list)
  print(number_list_final)
  </code></pre>
  
  <p>I know this is about iterating with the list while modifying it, but no idea how to fix it.</p>
  
  <p>Can anyone help me to debug this, or give me some tips?</p>
  
  <p>Thank you!</p>