1. 程式人生 > >str 轉 list or dict Python

str 轉 list or dict Python

1. 字串是連結串列的形式

str = '12, 24, 56, 58'
target_list = [int(x) for x in str.split(',')]
print target_list

>>>[12, 24, 56, 58]

2. 把字串直接轉換成list

str = 'abcde'
str_to_list = list(str)
print str_to_list

>>>['a', 'b', 'c', 'd', 'e']

3. 把list轉化為字串

str = 'abcde'
str_to_list = list(str)
str_convert = ''.join(str_to_list)
print str_convert