Re: [OT] Re: turn list of letters into an array of integers

2012-10-25 Thread Steven D'Aprano
On Thu, 25 Oct 2012 07:47:48 +0200, Peter Otten wrote: Wasn't there a Monty Python sketch where a man carrying a parrot in a cage comes into a shop full of stuffed animals and complains: No, I don't admire the taxidermist for making that parrot look like it were alive -- that beast bit me! I

Re: [OT] Re: turn list of letters into an array of integers

2012-10-25 Thread Peter Otten
Steven D'Aprano wrote: On Thu, 25 Oct 2012 07:47:48 +0200, Peter Otten wrote: Wasn't there a Monty Python sketch where a man carrying a parrot in a cage comes into a shop full of stuffed animals and complains: No, I don't admire the taxidermist for making that parrot look like it were

Re: [OT] Re: turn list of letters into an array of integers

2012-10-25 Thread Mark Lawrence
On 25/10/2012 09:25, Peter Otten wrote: Steven D'Aprano wrote: On Thu, 25 Oct 2012 07:47:48 +0200, Peter Otten wrote: Wasn't there a Monty Python sketch where a man carrying a parrot in a cage comes into a shop full of stuffed animals and complains: No, I don't admire the taxidermist for

RE: turn list of letters into an array of integers

2012-10-25 Thread Prasad, Ramit
David Hutto wrote: On Wed, Oct 24, 2012 at 1:23 AM, seektime michael.j.kra...@gmail.com 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,

Re: turn list of letters into an array of integers

2012-10-24 Thread Demian Brecht
Of course, if you want these to be ints, then you can either change the format of your int list, or map(int, list_) if you don't have control over it. Ugh, I'm tired. Shouldn't map it, the conversion should be done in the list comprehension to avoid a needless second list iteration. K, I'm

Re: turn list of letters into an array of integers

2012-10-24 Thread Chris Rebert
On Tue, Oct 23, 2012 at 10:23 PM, seektime michael.j.kra...@gmail.com 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: You mean a Python list. The datatype Python calls an `array` is very

Re: turn list of letters into an array of integers

2012-10-24 Thread Peter Otten
Chris Rebert wrote: line.strip().split() No need to strip() if you are going to split on whitespace: line = a b c \n line.split() == line.strip().split() True Lest the new idiom takes on while you are bravely fighting the immortable readlines() ;) --

Re: turn list of letters into an array of integers

2012-10-24 Thread Peter Otten
Peter Otten wrote: Brave new words: immortable should be immortal -- http://mail.python.org/mailman/listinfo/python-list

Re: turn list of letters into an array of integers

2012-10-24 Thread 88888 Dihedral
Chris Rebert於 2012年10月24日星期三UTC+8下午2時07分29秒寫道: On Tue, Oct 23, 2012 at 10:23 PM, seektime michael.j.kra...@gmail.com 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:

Re: turn list of letters into an array of integers

2012-10-24 Thread Robert Kern
On 10/24/12 1:03 PM, 8 Dihedral wrote: The list in python is a list of valid python objects. For the number crunching part, please use arrays in numarray and scipy. Your bot's database is laughably out of date. -- Robert Kern I have come to believe that the whole world is an enigma, a

Re: turn list of letters into an array of integers

2012-10-24 Thread Terry Reedy
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

Re: turn list of letters into an array of integers

2012-10-24 Thread MRAB
On 2012-10-24 07:07, Chris Rebert wrote: On Tue, Oct 23, 2012 at 10:23 PM, seektime michael.j.kra...@gmail.com 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: You mean a Python list. The

Re: turn list of letters into an array of integers

2012-10-24 Thread wxjmfauth
Le mercredi 24 octobre 2012 07:23:11 UTC+2, seektime a écrit : 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. Here's

Re: turn list of letters into an array of integers

2012-10-24 Thread Demian Brecht
On 2012-10-24, at 10:27 AM, wxjmfa...@gmail.com wrote: Not so sure what you mean by an array of integers. I wasn't entirely sure about that either. I assumed given the subject that it was just a 1-D array and could then be accessed by arr[(y * width) + x]. Demian Brecht @demianbrecht

Re: turn list of letters into an array of integers

2012-10-24 Thread seektime
On Tuesday, October 23, 2012 11:07:29 PM UTC-7, Chris Rebert wrote: On Tue, Oct 23, 2012 at 10:23 PM, seektime michael.j.kra...@gmail.com 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

Re: turn list of letters into an array of integers

2012-10-24 Thread Chris Rebert
On Wed, Oct 24, 2012 at 9:27 PM, seektime michael.j.kra...@gmail.com wrote: On Tuesday, October 23, 2012 11:07:29 PM UTC-7, Chris Rebert wrote: snip P.S.: I'm guessing you obtained `L` from file.readlines() or similar; it is worth noting for future reference that the readlines() method is

[OT] Re: turn list of letters into an array of integers

2012-10-24 Thread Peter Otten
Dennis Lee Bieber wrote: On Wed, 24 Oct 2012 11:04:38 +0200, Peter Otten __pete...@web.de declaimed the following in gmane.comp.python.general: Peter Otten wrote: Brave new words: immortable should be immortal Readlines() isn't immortal... It's a lich

Re: turn list of letters into an array of integers

2012-10-23 Thread Demian Brecht
On 2012-10-23, at 10:23 PM, seektime michael.j.kra...@gmail.com wrote: My question is how can I turn seq into a python array? Something like this perhaps?: alpha = ('a', 'b') numeric = ('1', '2') L = ['a b a\n', 'b b a\n'] s = ' '.join(L) d = dict(zip(alpha, numeric)) list_ = [d[c] for c

Re: turn list of letters into an array of integers

2012-10-23 Thread Demian Brecht
On 2012-10-23, at 10:45 PM, Demian Brecht demianbre...@gmail.com wrote: list_ = [d[c] for c in s.strip('\n').split()] list_ ['1', '2', '1', '2', '2', '1'] Of course, if you want these to be ints, then you can either change the format of your int list, or map(int, list_) if you don't have

Re: turn list of letters into an array of integers

2012-10-23 Thread David Hutto
On Wed, Oct 24, 2012 at 1:23 AM, seektime michael.j.kra...@gmail.com 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. Here's the code