如果一个字符串有一个来自我字典的值,我该如何打印这个值?

2024-10-02 12:28:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要找出邮件是否有我字典中的单词,如果有,我需要知道它是哪个单词,这样我就可以打印值,我有:

if any(word in message for word in diccionary):

所以我想做print(diccionary[thatword])。你知道吗


Tags: inmessageforif字典邮件any单词
3条回答

一个快速的选择:

next(word for word in dictionary if word in message)
for word, value in dictionary.items():
    if word in message:
        print(value)

这就是你要找的吗?你知道吗

for key, value in dictionary.items():
    if key in message:
        print(value)

相关问题 更多 >

    热门问题