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