Python version :Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
System version :Windows 10
System version :Windows 10
str1 = '背景,0,特性,1,元件,3'
list1 = str1.split(",")
dic1 = {list1[i]: list1[i+1] for i in range(0, len(list1), 2)}
print(list1)
print(dic1)
執行結果:
['背景', '0', '特性', '1', '元件', '3']
{'背景': '0', '特性': '1', '元件': '3'}
沒有留言:
張貼留言