像这样的东西,如果你的元组看起来像:(key1,value1,key2,value2,...)
In [25]: dict((my_tuple[i],my_tuple[i+1]) for i in xrange(0,len(my_tuple),2))
Out[25]: {'chess': ['650', 'John - Tom']}
使用字典理解:
In [26]: {my_tuple[i]: my_tuple[i+1] for i in xrange(0,len(my_tuple),2)}
Out[26]: {'chess': ['650', 'John - Tom']}
如果元组中的项目数不是很大:
In [27]: { k : v for k,v in zip( my_tuple[::2],my_tuple[1::2] )}
Out[27]: {'chess': ['650', 'John - Tom']}
使用迭代器:
In [36]: it=iter(my_tuple)
In [37]: dict((next(it),next(it)) for _ in xrange(len(my_tuple)/2))
Out[37]: {'chess': ['650', 'John - Tom']}