在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Python/ python str 與 list的轉(zhuǎn)換

python str 與 list的轉(zhuǎn)換

python如何在str和list之間轉(zhuǎn)換而不破壞原內(nèi)容。

例如 [{"key":"value"},{"key":"value"}] 轉(zhuǎn)到 '[{"key":"value"},{"key":"value"}]',然后再轉(zhuǎn)回[{"key":"value"},{"key":"value"}]

回答
編輯回答
久愛(ài)她

是這個(gè)意思嗎?

a_dic = [{'1': 1}, {'2': 2}]
a_str = str(a_dic)
print("type is {}, dic to str is {}".format(type(a_str), a_str))
a_dic = eval(a_str)
print ("type is {},str to dict is {}".format(type(a_dic), a_dic))
2017年8月9日 19:28