Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31991 > unrolled thread

turn list of letters into an array of integers

Started byseektime <michael.j.krause@gmail.com>
First post2012-10-23 22:23 -0700
Last post2012-10-25 21:27 +0000
Articles 4 on this page of 24 — 14 participants

Back to article view | Back to comp.lang.python


Contents

  turn list of letters into an array of integers seektime <michael.j.krause@gmail.com> - 2012-10-23 22:23 -0700
    Re: turn list of letters into an array of integers Demian Brecht <demianbrecht@gmail.com> - 2012-10-23 22:45 -0700
    Re: turn list of letters into an array of integers David Hutto <dwightdhutto@gmail.com> - 2012-10-24 01:50 -0400
    Re: turn list of letters into an array of integers Demian Brecht <demianbrecht@gmail.com> - 2012-10-23 22:51 -0700
    Re: turn list of letters into an array of integers Demian Brecht <demianbrecht@gmail.com> - 2012-10-23 22:54 -0700
    Re: turn list of letters into an array of integers Chris Rebert <clp2@rebertia.com> - 2012-10-23 23:07 -0700
      Re: turn list of letters into an array of integers 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-24 05:03 -0700
        Re: turn list of letters into an array of integers Robert Kern <robert.kern@gmail.com> - 2012-10-24 13:22 +0100
      Re: turn list of letters into an array of integers 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-24 05:03 -0700
      Re: turn list of letters into an array of integers seektime <michael.j.krause@gmail.com> - 2012-10-24 21:27 -0700
        Re: turn list of letters into an array of integers Chris Rebert <clp2@rebertia.com> - 2012-10-24 21:52 -0700
      Re: turn list of letters into an array of integers seektime <michael.j.krause@gmail.com> - 2012-10-24 21:27 -0700
    Re: turn list of letters into an array of integers Peter Otten <__peter__@web.de> - 2012-10-24 09:47 +0200
    Re: turn list of letters into an array of integers Peter Otten <__peter__@web.de> - 2012-10-24 11:04 +0200
    Re: turn list of letters into an array of integers Terry Reedy <tjreedy@udel.edu> - 2012-10-24 11:56 -0400
    Re: turn list of letters into an array of integers MRAB <python@mrabarnett.plus.com> - 2012-10-24 18:05 +0100
    Re: turn list of letters into an array of integers wxjmfauth@gmail.com - 2012-10-24 10:27 -0700
      Re: turn list of letters into an array of integers Demian Brecht <demianbrecht@gmail.com> - 2012-10-24 10:36 -0700
    Re: turn list of letters into an array of integers Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-24 15:57 -0400
    [OT] Re: turn list of letters into an array of integers Peter Otten <__peter__@web.de> - 2012-10-25 07:47 +0200
      Re: [OT] Re: turn list of letters into an array of integers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-25 07:49 +0000
        Re: [OT] Re: turn list of letters into an array of integers Peter Otten <__peter__@web.de> - 2012-10-25 10:25 +0200
        Re: [OT] Re: turn list of letters into an array of integers Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-25 09:55 +0100
    RE: turn list of letters into an array of integers "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-25 21:27 +0000

Page 2 of 2 — ← Prev page 1 [2]


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

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-10-25 07:49 +0000
SubjectRe: [OT] Re: turn list of letters into an array of integers
Message-ID<5088ef16$0$29882$c3e8da3$5496439d@news.astraweb.com>
In reply to#32091
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 don't think so. Are you thinking of the famous Monty Python "Dead 
Parrot Sketch"? Here's one of many versions:

http://www.youtube.com/watch?v=4vuW6tQ0218



-- 
Steven

[toc] | [prev] | [next] | [standalone]


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

FromPeter Otten <__peter__@web.de>
Date2012-10-25 10:25 +0200
SubjectRe: [OT] Re: turn list of letters into an array of integers
Message-ID<mailman.2814.1351153517.27098.python-list@python.org>
In reply to#32094
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
>> alive -- that beast bit me!
> 
> I don't think so. Are you thinking of the famous Monty Python "Dead
> Parrot Sketch"? Here's one of many versions:
> 
> http://www.youtube.com/watch?v=4vuW6tQ0218

My rendition was meant to be a travesty of that one, an "undead" parrot as a 
follow-up to Dennis' "lich" post. I'm sorry I forgot the smiley ;)

- He didn't move, that was just the wind stirring his plumage.
- No, that parrot is alive and kicking, fresh as a daisy, full of beans...
- Aren't the glass eyes beautiful?
- Glass eyes -- he just blinked!

And so on. I'm off to work on my laden swallow branch of Python. It's going 
to be a real heavy-weight...

-- 
Always look on the dark side of death

[toc] | [prev] | [next] | [standalone]


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

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-10-25 09:55 +0100
SubjectRe: [OT] Re: turn list of letters into an array of integers
Message-ID<mailman.2815.1351155099.27098.python-list@python.org>
In reply to#32094
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 making that parrot look like it were
>>> alive -- that beast bit me!
>>
>> I don't think so. Are you thinking of the famous Monty Python "Dead
>> Parrot Sketch"? Here's one of many versions:
>>
>> http://www.youtube.com/watch?v=4vuW6tQ0218
>
> My rendition was meant to be a travesty of that one, an "undead" parrot as a
> follow-up to Dennis' "lich" post. I'm sorry I forgot the smiley ;)
>
> - He didn't move, that was just the wind stirring his plumage.
> - No, that parrot is alive and kicking, fresh as a daisy, full of beans...
> - Aren't the glass eyes beautiful?
> - Glass eyes -- he just blinked!
>
> And so on. I'm off to work on my laden swallow branch of Python. It's going
> to be a real heavy-weight...
>

I just hope you get the technicalities correct.  "That parrot wouldn't 
move if you put 4 million volts through it".  What rubbish.  It should 
either have been 4 million amps through it or 4 million volts across it. 
  I'm +1 for the former, although possibly biased by history.

-- 
Cheers.

Mark Lawrence.

[toc] | [prev] | [next] | [standalone]


#32170

From"Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Date2012-10-25 21:27 +0000
Message-ID<mailman.2870.1351200457.27098.python-list@python.org>
In reply to#31991
David Hutto wrote:
> On Wed, Oct 24, 2012 at 1:23 AM, seektime <michael.j.krause@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 I have so far:
> >
> >>>> L=['a b a\n','b b a\n']
> >>>> s=' '.join(L)
> >>>> seq1=('a','b')
> >>>> seq2=('1','2')
> >>>> d = dict(zip(seq1,seq2))
> >>>> # Define method to replace letters according to dictionary (got this from
> http://gommeitputor.wordpress.com/2008/09/27/search-replace-multiple-words-or-characters-with-python/).
> > ... def replace_all(text, dic):
> > ...     for i, j in dic.iteritems():
> > ...         text = text.replace(i, j)
> > ...     return text
> > ...
> >
> >>>> seq = replace_all(s,d)
> >>>> print seq
> > 1 2 1
> >  2 2 1
> >
> >>>> seq
> > '1 2 1\n 2 2 1\n'
> >
> I'd suggest, if this is what you're referring to:
> 
> x = seq.split('\n  ')
> array_list = [ ]
> next_3_d_array = []
> range_of_seq = len(seq)
> for num in range(0,range_of_seq):
>        if num % 3 != 0:
>                next_3_d_array.append(num)
>        if num % 3 == 0:
>                    array_list.append(next_3_d_array)
>                    next_3_d_array = [ ]
> 

Wow, that looks complicated. Why hardcode to 3 instead of where ever
the newline is?

>>> [ int(x.strip()) for subseq in seq.split('\n') for x in subseq.split() ]
[1, 2, 1, 2, 2, 1]
>>> lst = []
# OR
>>> for subseq in seq.split('\n'):
...     for x in subseq.split():
...         lst.append( int(x.strip()))
...     
>>>

Ramit Prasad


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web