تخطَّ إلى المحتوى

Combine collection predicates (ARCH2077)

هذا المحتوى غير متوفر بلغتك بعد.

Key python.performance.combine-collection-predicates · Severity info · Category performance

Consecutive filters can be fused into a single condition, and using any(...) instead of len(...) > 0 for an emptiness check avoids a needless full pass.

def has_urgent(tickets):
open_t = [t for t in tickets if t.is_open]
urgent = [t for t in open_t if t.priority == "urgent"]
return len(urgent) > 0
def has_urgent(tickets):
return any(t.is_open and t.priority == "urgent" for t in tickets)

Fuse consecutive filters into one condition and use any(...) for presence checks.