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)

相關文章
相關標籤/搜索