[Tutor] string to list

Owain Clarke simbobo at cooptel.net
Wed Feb 10 13:34:02 CET 2010


I have solved it myself - must search more before posting!

If anyone at my kind of level is interested:-

 >>> mystring = "[(1,2), (3,4)]"
 >>> mylist = eval(mystring)
 >>> mylist
[(1,2), (3,4)]
 >>> type(mylist)
<type 'list'>

Thanks

Owain Clarke wrote:
> Please excuse the obviousness of my question (if it is), but I have 
> searched the documentation for how to generate a list e.g. [(1,2), 
> (3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point 
> me in the right direction.
>
> Many thanks
>
> Owain Clarke
>


More information about the Tutor mailing list