title: Python bit list to byte list
body: <p>I have a long 1-dimensional list of integer 1's and 0's, representing 8-bit binary bytes. What is a <em>neat</em> way to create a new list from that, containing the integer bytes.</p>
  
  <p>Being familiar with C, but new to Python, I've coded it in the way I'd do it with C: an elaborate structure that loops though each bit. However, I'm aware that the whole point of Python over C is that such things can usually be done compactly and elegantly, and that I should learn how to do that. Maybe using list comprehension?</p>
  
  <p>This works, but suggestions for a more "Pythonic" way would be appreciated:</p>
  
  <pre><code>#!/usr/bin/env python2
  bits = [1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,1,1,0,0,1,1,1]
  bytes = []
  byt = ""
  for bit in bits:
    byt += str(bit)
    if len(byt) == 8:
      bytes += [int(byt, 2)]
      byt = ""
  print bytes
  
  $ bits-to-bytes.py
  [149, 107, 231]
  </code></pre>