开发者

using method as function in python

Say I have a list of strings, and I wan开发者_如何学编程t to filter out all non-upper case strings. Is there a simpler way than doing filter(lambda x: x.isupper(), list)?


While I would prefer a list comprehension, this seems to be what you're looking for:

filter(str.isupper, list)


uppers = [s for s in list if s.isupper()]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜