1.字符串转列表
str1 = '你 是 不 是 我 最 疼 爱 的 人' new_str = list(str1.split()) print('字符串转列表',new_str,type(new_str))
2.列表转字符串
lis = ["你","是","不","是","我","最","疼","爱","的","人"] new_lis = ''.join(lis) print('列表转字符串',new_lis,type(new_lis))
3.字符串转字典
str2 = '{"name":"老王","age":18,"addr":"长沙" }' new_dict = eval(str2) print('字符串转字典',new_dict,type(new_dict))
4.字典转字符串
dict1 = {"name":"老王","age":18,"addr":"长沙" } new_str1 = str(dict1) print('字典转字符串',new_str1,type(new_str1))
5.列表合并字典
list1 = ["姓名","年龄","地址"] list2 = ["老王",18,"北京"] list3 = dict(zip(list1,list2)) print('合并后的字典',list3,type(list3))
6.字典拆分为列表
dic1 = {"name":"老王","age":18,"addr":"长沙" } list_key = list(dic1.keys()) list_value = list(dic1.values()) print('key列表为:{}\nvalue列表为:{}'.format(list_key,list_value))