Turns out I was close but had not combined everything. I never would have picked up on the map() function. Much more efficient than looping through the whole mess and converting to int.

x = ['[335, 180, 201, 241, 199]\r\n']
y = map( int, x[0].strip( '[]\r\n' ).split(  ', '  ) ) #need an index here
print y
[335, 180, 201, 241, 199]

Thanks for your help!

kbk

Kent Johnson wrote:
For one line:
In [11]: s = '[335, 180, 201, 241, 199]\r\n'

In [12]: map(int, s.strip('[]\r\n').split(', '))
Out[12]: [335, 180, 201, 241, 199]

Modify appropriately to handle a list of lines.

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to