2
我想兩個字符串的值轉換成單一的字典這樣如何將兩個字符串轉換爲單個字典?
string1='red blue white'
string2= 'first second third'
dict={'red':first,'blue':second.'white':third}
但在這裏我不能使用循環!有沒有其他方式沒有循環? 幫幫我! 謝謝
我想兩個字符串的值轉換成單一的字典這樣如何將兩個字符串轉換爲單個字典?
string1='red blue white'
string2= 'first second third'
dict={'red':first,'blue':second.'white':third}
但在這裏我不能使用循環!有沒有其他方式沒有循環? 幫幫我! 謝謝
>>> string1 = 'red blue white'
>>> string2 = 'first second third'
>>> dict(zip(string1.split(), string2.split()))
{'blue': 'second', 'red': 'first', 'white': 'third'}
非常感謝你! – Vilva
爲什麼你不能使用循環?這是功課嗎? –
我其實我試圖用大量的數據,由於python的慢我正在避免循環 – Vilva