title: python function to split a list by indexes
body: <p>I am trying to build an efficient function for splitting a list of any size by any given number of indices. This method works and it took me a few hours to get it right (I hate how easy it is to get things wrong when using indexes) </p>
  
  <p>Am I over-thinking this?</p>
  
  <p>Code:</p>
  
  <p>def lindexsplit(List,*lindex):</p>
  
  <pre><code>index = list(lindex)
  
  index.sort()
  
  templist1 = []
  templist2 = []
  templist3 = []
  
  breakcounter = 0
  itemcounter = 0
  finalcounter = 0
  
  
  numberofbreaks = len(index)
  totalitems = len(List)
  
  lastindexval = index[(len(index)-1)]
  finalcounttrigger = (totalitems-(lastindexval+1))
  
  for item in List:
  
      itemcounter += 1
  
      indexofitem = itemcounter - 1
  
      nextbreakindex = index[breakcounter]
  
      #Less than the last cut
      if breakcounter &lt;= numberofbreaks:
  
          if indexofitem &lt; nextbreakindex:
  
              templist1.append(item)
  
          elif breakcounter &lt; (numberofbreaks - 1):
  
              templist1.append(item)
  
              templist2.append(templist1)
  
              templist1 = []
  
              breakcounter +=1
  
          else:
  
              if indexofitem &lt;= lastindexval and indexofitem &lt;= totalitems:
  
                  templist1.append(item)
  
                  templist2.append(templist1)
  
                  templist1 = []
  
              else:
  
                  if indexofitem &gt;= lastindexval and indexofitem &lt; totalitems + 1:
  
                      finalcounter += 1
  
                      templist3.append(item)
  
                      if finalcounter == finalcounttrigger:
  
                          templist2.append(templist3)
  
  
  return templist2
  </code></pre>