#23968 closed Cleanup/optimization (fixed)
Use generator comprehension instead of list comprehension when possible
Reported by: | Jon Dufresne | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | jon.dufresne@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Small cleanup to use generator comprehension instead of list comprehension when the called function can easily accept both. This avoids an extra list instance, thus avoid the small overhead of the temporary list.
For example, prefer:
tuple(force_text(item) for item in lst)
over:
tuple([force_text(item) for item in lst])
Patch to follow. Fixes uses of the following functions throughout the codebase.
dict() tuple() any() all() min() max() sorted() list.extend() list +=
Change History (5)
comment:1 Changed 9 years ago by
Cc: | jon.dufresne@… added |
---|---|
Has patch: | set |
comment:2 Changed 9 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 Changed 9 years ago by
Triage Stage: | Accepted → Ready for checkin |
---|
comment:4 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
https://github.com/django/django/pull/3701