python - Python 函数中输出列表元素 "any"

标签 python list any

我是 Python 的新手,我无法在 any 函数中正确输出日期。 Any函数返回TrueFalse,但我想输出列表元素。示例如下:

days = ["monday","tuesday","wednesday","thursday","friday"]
if any(day in content.lower() for day in days):
    print day

我想打印哪一天,函数在字符串“content”中找到了。内容一次只有一天。有没有一种简单的方法可以做到这一点?

最佳答案

我想你想要的是:

print [day for day in days if day in content.lower()]

这将为您提供所有匹配日期的列表。

关于python - Python 函数中输出列表元素 "any",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31201971/

相关文章:

python - Python 中是否有_rational_ 区间算术的实现?

python - 如何对二维列表进行排序?

swift - 如何使用 swift 解析字典中的 Any

python - 如何检查数据框中是否有值

python - seek(),然后是 read(),然后是 python 中的 write()

python - 根据路径列表导入图像

python - 在 OpenCV Python 中与多个对象进行模板匹配

CSS 和 z-index : child element under parent element in a list

C++ 列表迭代器在遍历时永远不会到达 end()

hibernate 3.6.7 : Problem with @ANY and Foreign-Key