title: How do you convert a list of characters and bytes into a list of pure bytes?
body: <p>I have a list which is a mixture of characters and bytes, which looks like this :</p>
  
  <pre><code>myData = ['a', '\x65', 'B', '\x66\x69', 'C']
  </code></pre>
  
  <p>I want to convert this list into a byte array, so this :</p>
  
  <pre><code>myByteArray = ['\x61' , '\x65', '\x42', '\x66', '\x69', '\x43']
  </code></pre>
  
  <p>What I have tried so far is a simple display on myData --</p>
  
  <pre><code>myData = ['a', '\x65', 'B', '\x66\x69', 'C']
  print " ".join(hex(ord(n)) for n in myData)
  </code></pre>
  
  <p>Since there is an element in the array that happens to be two bytes, it throws this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./test.py", line 3, in &lt;module&gt;
      print " ".join(hex(ord(n)) for n in myData)
    File "./test.py", line 3, in &lt;genexpr&gt;
      print " ".join(hex(ord(n)) for n in myData)
  TypeError: ord() expected a character, but string of length 2 found
  </code></pre>
  
  <p>How can I convert my original list, myData, into a byte array, myByteArray?</p>