Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#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 8 years ago by Jon Dufresne

Cc: jon.dufresne@… added
Has patch: set

comment:2 Changed 8 years ago by Collin Anderson

Triage Stage: UnreviewedAccepted

comment:3 Changed 8 years ago by Collin Anderson

Triage Stage: AcceptedReady for checkin

comment:4 Changed 8 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 4468c08d70b5b722f3ebd4872909e56580ec7d68:

Fixed #23968 -- Replaced list comprehension with generators and dict comprehension

comment:5 Changed 6 years ago by Tim Graham <timograham@…>

In 2c69824e:

Refs #23968 -- Removed unnecessary lists, generators, and tuple calls.

Note: See TracTickets for help on using tickets.
Back to Top