#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 (6)
comment:1 by , 11 years ago
| Cc: | added |
|---|---|
| Has patch: | set |
comment:2 by , 11 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 11 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:4 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
https://github.com/django/django/pull/3701