我有一个字符串。现在,如果两个不同列表中的任何内容匹配,我想将字符串拆分为多个部分。我怎样才能做到这一点 ?我有什么。
dummy_word = "I have a HTML file"
dummy_type = ["HTML","JSON","XML"]
dummy_file_type = ["file","document","paper"]
for e in dummy_type:
if e in dummy_word:
type_found = e
print("type ->" , e)
dum = dummy_word.split(e)
complete_dum = "".join(dum)
for c in dummy_file_type:
if c in complete_dum:
then = complete_dum.split("c")
print("file type ->",then)
在给定的场景中,我的预期输出是["I have a", "HTML","file"]