Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Python 3 中,检查谓词是否对字符串的所有字符都为真的最短方法是什么?
all(predicate(x) for x in string)
all(map(predicate, string))
功能上与@Abe 的答案相同,但使用 map 代替(在 python3 中也很懒惰)