CromTheDestroyer
CromTheDestroyer

Reputation: 3766

using method as function in python

Say I have a list of strings, and I want to filter out all non-upper case strings. Is there a simpler way than doing filter(lambda x: x.isupper(), list)?

Upvotes: 0

Views: 142

Answers (2)

manji
manji

Reputation: 47978

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

Upvotes: 5

Cosmologicon
Cosmologicon

Reputation: 2167

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

filter(str.isupper, list)

Upvotes: 10

Related Questions