title: Trying to make function that simplifies a list of integers by grouping repeats
body: <p>I want to make a function in python that takes a list with more than 1 element of numerically ordered integers as an input and returns a list of the same integers as an output but any repeats are grouped together in a list of their own, with this list being an element within the returned list by the function. For example:</p>
  
  <p><code>[3,3,4,4,4,5,6,6]</code> will return as <code>[[3,3],[4,4,4],5,[6,6]]</code></p>
  
  <p>I've tried to embed multiple if statements for each condition but that gets way too messy, way too quickly.</p>
  
  <pre><code>def simplify(mylist):
      if len(mylist) &gt; 1:
          newlist = []
          for i in range(0, len(mylist) - 1):
              if (mylist[i] == mylist[i + 1]):
                  count = 2
                  group = [mylist[i], mylist[i]]
                  while (i + count) &lt;= (len(mylist) - 1):
                      if mylist[i] == mylist[i + count]:
                          group.append(mylist[i])
                          count += 1
                      else:
                          newlist.append(group)
                          break
              else:
                  newlist.append(mylist[i])
          print(newlist)
          return (newlist)
  </code></pre>
  
  <p>So I expected it to do what I described the function should do but then it resulted in a list with elements that repeated being repeated in lists decreasing by one element until it finished iterating and did not append the last value. Example:</p>
  
  <p>input <code>[3,4,4,4,4,5]</code></p>
  
  <p>returned <code>[3,[4,4,4,4],[4,4,4],[4,4],4]</code></p>