为了账号安全,请及时绑定邮箱和手机立即绑定

字典只返回部分答案(也许是关于缩进)

字典只返回部分答案(也许是关于缩进)

蝴蝶刀刀 2021-07-22 17:12:03
def main():    file=[['mississippi', 'worth', 'reading','river'], ['commonplace', 'river', 'contrary', 'ways', 'remarkable']]    print(set_and_count(file))def set_and_count(common_deleted):    sets=list(set(common_deleted[0]))    for i in range(len(common_deleted)):        ## make a non-repeated word list        sets=list(set(sets+common_deleted[i]))    ## initialize dict    dict_wordloc={}    for j in range(len(sets)):        sublist=[]        count_time=0        for k in range(len(common_deleted)):            if sets[j]  in common_deleted[k]:                count_time+=1                sublist.append(k)                dict_wordloc[sets[k]]=count_time,sublist    return(dict_wordloc)main()问题一:代码只返回部分答案在示例输入文件中,字典中的键必须是 'mississippi'、'worth'、'reading'、'river'、'commonplace'、'contrary'、'ways'、'remarkable'但是当我运行代码时,它返回:{'remarkable': (2, [0, 1]), 'ways': (1, [0, 1])}每次我运行它,返回的东西都不一样例如,当我运行它两次时,结果是{'contrary': (2, [0, 1]), 'ways': (1, [0, 1])}问题 2:答案错误,在 Prob 1 的输出中,在 key 中remarkable,值必须是(1,[1])元组中的第一项是有多少个句子有这个词(嵌套列表是一个句子)元组中的第二项是包含该词的句子 NO
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 111 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信