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()]
精彩评论