Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 从两个句子中找出缺少的单词_Python 3.x - Fatal编程技术网

Python 3.x 从两个句子中找出缺少的单词

Python 3.x 从两个句子中找出缺少的单词,python-3.x,Python 3.x,有两个字符串,s和t,其中t是s的子序列,按缺失顺序报告tcase SENSTIVE中缺失的s单词 限制条件: 字符串s和t仅由英文字母、破折号和空格组成。 所有单词都用空格分隔 示例:如果s=我正在使用计算机改进我的工作,而t=我正在使用计算机改进我的工作,那么缺少的单词的输出应该是:我正在使用我的工作这是你的家庭作业吗?到目前为止你做了什么? s = " I am using computer to improve my work" t = "am computer to improve

有两个字符串,s和t,其中t是s的子序列,按缺失顺序报告tcase SENSTIVE中缺失的s单词

限制条件: 字符串s和t仅由英文字母、破折号和空格组成。 所有单词都用空格分隔


示例:如果s=我正在使用计算机改进我的工作,而t=我正在使用计算机改进我的工作,那么缺少的单词的输出应该是:我正在使用我的工作

这是你的家庭作业吗?到目前为止你做了什么?
s = " I am using computer to improve my work"  
t = "am computer to improve"
s_list=s.split()
t_list=t.split()

# Using set() 
def Diff1(li1, li2): 
    return (list(set(li1) - set(li2)))

# Not using set() 
def Diff2(li1, li2): 
    li_dif = [i for i in li1 + li2 if i not in li1 or i not in li2] 
    return li_dif

if __name__ == "__main__":
    print(Diff1(s_list,t_list))
    print(Diff2(s_list,t_list))