On 10/24/2012 1:23 AM, seektime wrote:
Here's some example code. The input is a list which is a "matrix" of letters:
    a  b  a
    b  b  a

and I'd like to turn this into a Python array:

   1 2 1
   2 2 1

so 1 replaces a, and 2 replaces b.

If you are going to replace single characters (letters) with single characters (digits), use maketrans and translate.

>>> 'a b c'.translate(str.maketrans('abc', '123'))
'1 2 3'

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to