On Mon, Oct 4, 2010 at 6:10 PM, Mark Phillips
<m...@phillipsmarketing.biz> wrote:
> I have the following string - "['1', '2']" that I need to convert into a
> list of integers - [1,2]. The string can contain from 1 to many integers. Eg
> "['1', '7', '4',......,'n']" (values are not sequential)
>
> What would be the best way to do this? I don't want to use eval, as the
> string is coming from an untrusted source.

integers = [int(num) for num in string[1:-1].replace("'", "").split(",")]

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to