Re: Converting List of String to Integer

2008-07-22 Thread Samir
Wow! Thanks for all of the great additional feedback and responses since I last checked in. The help this group provides is amazing. I'm glad I found it. @Andrew -- Thanks for the clarification on the nested for loop and how to intrepret it. Also, thanks for the information on generators. I ha

Re: Converting List of String to Integer

2008-07-22 Thread ptn
> n = [] > for k in a: >     n.append([int(v) for v in k]) > print n > > Does anyone know what I am doing wrong? > > Thanks in advance. > > Samir Use extend instead of append: * Append -> add the one item to the end of the list * Extend -> add the list of items to the end of the list -- http://ma

Re: Converting List of String to Integer

2008-07-22 Thread Rishabh Manocha
Just to throw my hat in the ring, this is another way you can do this: [(lambda x : [int(ii) for ii in x])(y) for y in a] However, I do think dusans way is more elegant. Best, R On Tue, Jul 22, 2008 at 4:58 PM, dusans <[EMAIL PROTECTED]> wrote: > >>> a = [['1', '2'], ['3'], ['4', '5', '6'], [

Re: Converting List of String to Integer

2008-07-22 Thread dusans
>>> a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']] >>> [map(int, i) for i in a] [[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]] On Jul 21, 9:06 pm, Samir <[EMAIL PROTECTED]> wrote: > Hi Everyone, > > I am relatively new to Python so please forgive me for what seems like > a basic question.

Re: Converting List of String to Integer

2008-07-21 Thread Andrew Freeman
Samir wrote: For my small list, I didn't notice a discernible increase in speed, but I may have to try it with a larger list size. About speed, and memory consumption: List comprehensions (http://docs.python.org/tut/node7.html#SECTION00714) are just shortcuts for for-loops.

Re: Converting List of String to Integer

2008-07-21 Thread Andrew Freeman
Samir wrote: On Jul 21, 6:15 pm, Andrew Freeman <[EMAIL PROTECTED]> wrote: Samir wrote: On Jul 21, 3:20 pm, Gary Herron <[EMAIL PROTECTED]> wrote: Samir wrote: Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic quest

Re: Converting List of String to Integer

2008-07-21 Thread Samir
On Jul 21, 6:15 pm, Andrew Freeman <[EMAIL PROTECTED]> wrote: > Samir wrote: > > On Jul 21, 3:20 pm, Gary Herron <[EMAIL PROTECTED]> wrote: > > >> Samir wrote: > > >>> Hi Everyone, > > >>> I am relatively new to Python so please forgive me for what seems like > >>> a basic question. > > >>> Assume

Re: Converting List of String to Integer

2008-07-21 Thread Andrew Freeman
Samir wrote: On Jul 21, 3:20 pm, Gary Herron <[EMAIL PROTECTED]> wrote: Samir wrote: Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic question. Assume that I have a list, a, composed of nested lists with string representations o

Re: Converting List of String to Integer

2008-07-21 Thread Samir
On Jul 21, 4:44 pm, Gary Herron <[EMAIL PROTECTED]> wrote: > Samir wrote: > > On Jul 21, 3:20 pm, Gary Herron <[EMAIL PROTECTED]> wrote: > > >> Samir wrote: > > >>> Hi Everyone, > > >>> I am relatively new to Python so please forgive me for what seems like > >>> a basic question. > > >>> Assume tha

Re: Converting List of String to Integer

2008-07-21 Thread Gary Herron
Samir wrote: On Jul 21, 3:20 pm, Gary Herron <[EMAIL PROTECTED]> wrote: Samir wrote: Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic question. Assume that I have a list, a, composed of nested lists with string representations o

Re: Converting List of String to Integer

2008-07-21 Thread John Machin
On Jul 22, 6:11 am, Samir <[EMAIL PROTECTED]> wrote: [snip] > For some reason, the logic I posted seems to work ok while I'm using > the Python shell, but when used in my code, the program just hangs. > It never outputs the results. Below is the code in its entirety. Is > there a problem with my

Re: Converting List of String to Integer

2008-07-21 Thread Samir
On Jul 21, 3:20 pm, Gary Herron <[EMAIL PROTECTED]> wrote: > Samir wrote: > > Hi Everyone, > > > I am relatively new to Python so please forgive me for what seems like > > a basic question. > > > Assume that I have a list, a, composed of nested lists with string > > representations of integers, suc

Re: Converting List of String to Integer

2008-07-21 Thread Gary Herron
Samir wrote: Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic question. Assume that I have a list, a, composed of nested lists with string representations of integers, such that a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']] I would l

Converting List of String to Integer

2008-07-21 Thread Samir
Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic question. Assume that I have a list, a, composed of nested lists with string representations of integers, such that a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']] I would like to convert