string to list? possible?

Ewald ehoute at zeelandnet_dot_nl
Mon Jan 21 06:17:53 EST 2002


Piet van Oostrum <piet at cs.uu.nl> wrote in news:wzvgdwyrhb.fsf at cs.uu.nl:

>>>>>> Ewald <ehoute at zeelandnet_dot_nl> (E) writes:
> 
> E> Or less ugly:
> E> a = '[1,2,3,4]'
> E> map(int,filter(lambda x:x.isdigit(),a))
> 
> Now try this with a = '[11,12,13,1234]'
> 

Well i guess i didn't test it enough. But
map(int,a[1:-1].split(','))
or 
[int(x) for x in a[1:-1].split(',')]
should be ok, but will only work for integers (<=sys.maxint) inside the 
list.



More information about the Python-list mailing list