This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lgeiger
Recipients lgeiger
Date 2019-02-19.16:05:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1550592309.68.0.760031675356.issue36039@roundup.psfhosted.org>
In-reply-to
Content
Lib uses loops to append to a new list in quite a few places. I think it would be better to replace those with list comprehensions.

Benefits of this change:
  - List comprehensions are generally more readable than appending to a newly created list
  - List comprehensions are also a lot faster.
    Toy example:
    In [1]: %%timeit
       ...: l = []
       ...: for i in range(5000):
       ...:     l.append(i)
    375 µs ± 1.73 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

    In [2]: %%timeit
       ...: l = [i for i in range(5000)]
    168 µs ± 1.08 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

Possible drawbacks:
  - Refactoring can always introduce bugs and makes it harder to get meaningful output from git blame. In this case I think the diff is very manageable, making the changes easy to review.

Personally, I think the codebase would benefit from this change both in terms of some small performance gains and maintainability. I'd be happy to make a PR to fix this.
History
Date User Action Args
2019-02-19 16:05:09lgeigersetrecipients: + lgeiger
2019-02-19 16:05:09lgeigersetmessageid: <1550592309.68.0.760031675356.issue36039@roundup.psfhosted.org>
2019-02-19 16:05:09lgeigerlinkissue36039 messages
2019-02-19 16:05:09lgeigercreate