Python - 列表与字典相互转换

字符串转列表ide

s = 'abc'spa

a = list(s)字符串

['a','b','c']it


列表转为字符串class

''.join(a)im


字符串转换为元组dict

s='abc'di

t = tuple(s)view


元组转换为字符串vi

''.join(t)


列表转换为元组

l = ['a','b','c']

tuple(l)


元组转换为列表

t = ('a','b','c')

list(t)

['a','b','c']


字典转换为列表

dic={'a':1,'b':2}

dic.items()

[('a',1),('b',2)]

列表转换为字典

list1 = dic.items()

dict(list1)

相关文章
相关标签/搜索