0

Suppose a string s="[1,2,3]"

I want the list to be l=[1,2,3], where type(l) is list


How can I achieve this

user5319825
  • 491
  • 1
  • 6
  • 16

2 Answers2

0

Try this ,

In [3]:  l = eval(s)

In [4]: print l
[1, 2, 3]
Kenly
  • 24,317
  • 7
  • 44
  • 60
Rahul K P
  • 15,740
  • 4
  • 35
  • 52
  • 4
    You shouldn't suggest [very dangerous functions like `eval`](http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html) when there are better options. – Matthias Nov 24 '16 at 10:20
0
import json

s="[1,2,3]"
s_list = json.loads(s)
print(type(s_list))

out:

<type 'list'>
宏杰李
  • 11,820
  • 2
  • 28
  • 35