创建一个function叫follows(words_list),return 一个dictionary每个key的value是一个list包含key后面一个字
例子:
follows(['what', 'is', 'that', 'there'])
{'what': ['is'], 'is': ['that'], 'that': ['there']}
follows(['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish', 'blue'])
{'one': ['fish'], 'fish': ['two', 'red', 'blue', 'blue'], 'two': ['fish'], 'red': ['fish'], 'blue': ['fish']}
follows(['a', 'b', 'c', 'b', 'a', 'c', 'a', 'd', 'e', 'b', 'a'])
{'a': ['b', 'c', 'd'], 'b': ['c', 'a', 'a'], 'c': ['b', 'a'], 'd': ['e'], 'e': ['b']}
follows(['That', 'sam-i-am,', 'that', 'sam-i-am,', 'I', 'do', 'not', 'like', 'that', 'sam-i-am.', 'Do', 'you', 'like', 'green', 'eggs', 'and', 'ham?', 'I', 'do', 'not', 'like', 'them', 'sam-i-am.'])
{'That': ['sam-i-am,'], 'sam-i-am,': ['that', 'I'], 'that': ['sam-i-am,', 'sam-i-am.'], 'I': ['do', 'do'], 'do': ['not', 'not'], 'not': ['like', 'like'], 'like': ['that', 'green', 'them'], 'sam-i-am.': ['Do'], 'Do': ['you'], 'you': ['like'], 'green': ['eggs'], 'eggs': ['and'], 'and': ['ham?'], 'ham?': ['I'], 'them': ['sam-i-am.']}
def follows(words_list):
output={}
lis=[]
for i in range(len(words_list)):
lis.append(words_list.index(words_list[i]))
for g in range(len(lis)):
if g!=len(lis)-1:
然后怎么写