2011-11-05 49 views
2

我想两个字符串的值转换成单一的字典这样如何将两个字符串转换为单个字典?

string1='red blue white' 
string2= 'first second third' 
dict={'red':first,'blue':second.'white':third} 

但在这里我不能使用循环!有没有其他方式没有循环? 帮帮我! 谢谢

+1

为什么你不能使用循环?这是功课吗? –

+0

我其实我试图用大量的数据,由于python的慢我正在避免循环 – Vilva

回答

6
>>> string1 = 'red blue white' 
>>> string2 = 'first second third' 
>>> dict(zip(string1.split(), string2.split())) 
{'blue': 'second', 'red': 'first', 'white': 'third'} 
+0

非常感谢你! – Vilva

相关问题