test='i am a student'
test_split=test.split()
word_dict=dict((word,index) for word,index in enumerate(test_split))
print(word_dict,type(word_dict))
输出
当我们调整word与index的顺序时
test_split=test.split()
word_dict=dict((word,index) for index,word in enumerate(test_split))
print(word_dict,type(word_dict))