【发布时间】:2022-01-16 04:28:10
【问题描述】:
我认为最好用一个例子来说明这一点。
我有 RE 模式 choco_icecream = "(do|does) \w+ (loves|love|likes|like) (choco|chocolate) (ice-cream|icecream|ice cream)"。
我想检查example = "Does Jessica like Chocolate Icecream".lower() 是否与choco_icecream 匹配。
example 是choco_icecream 的匹配项,但我想知道example 的哪个单词对应choco_icecream 的元素。
我想要一本字典。理想的输出如下所示:{"(do|does)":"does", "\w+":"jessica", "(loves|love|likes|like)":"like", "(choco|chocolate)":"chocolate", "(ice-cream|icecream|ice cream)":"icecream"}
我怎样才能做到这一点?
【问题讨论】:
标签: python python-3.x dictionary word python-re