骑骡子赶猪  

例1

a='{"value":"2016","count":2,"desc":2016},{"value":"2015","count":2,"desc":2015},{"value":"2014","count":1,"desc":2014},{"value":"2013","count":2,"desc":2013},{"value":"2011","count":2,"desc":2011},{"value":"2010","count":1,"desc":2010},{"value":"2009","count":1,"desc":2009},{"value":"2006","count":3,"desc":2006},{"value":"2004","count":1,"desc":2004},{"value":"LTE2003","count":5,"desc":"2003\\u53ca\\u4ee5\\u524d"}, {"value":"2016","count":2,"desc":2016},{"value":"2015","count":2,"desc":2015},{"value":"2014","count":1,"desc":2014},{"value":"2013","count":2,"desc":2013},{"value":"2011","count":2,"desc":2011},{"value":"2010","count":1,"desc":2010},{"value":"2009","count":1,"desc":2009},{"value":"2006","count":3,"desc":2006},{"value":"2004","count":1,"desc":2004},{"value":"LTE2003","count":5,"desc":"2003\\u53ca\\u4ee5\\u524d"}'
print(list(eval(a)))


第二种正则(狠人专用)

 

eval函数就是实现list、dict、tuple与str之间的转化
str函数把list,dict,tuple转为为字符串

一、字符串转换成列表

a = "[[1,2], [3,4], [5,6], [7,8], [9,0]]"
print(type(a))
b = eval(a)
print(type(b)) print(b)


二、字符串转换成字典

a = "{1: 'a', 2: 'b'}"
print(type(a))
b = eval(a)
print(type(b))
print(b)

三、字符串转换成元组

a = "([1,2], [3,4], [5,6], [7,8], (9,0))"
print(type(a))
b=eval(a)
print(type(b))
print(b)

 

posted on 2019-10-11 15:40  骑骡子赶猪  阅读(387)  评论(0编辑  收藏  举报