Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Prefer literals over list and dict functions #1454

Merged
merged 2 commits into from
Mar 1, 2019

Conversation

lgeiger
Copy link
Contributor

@lgeiger lgeiger commented Feb 15, 2019

This is just some search and replace to improve readability:

  • d = dict() --> d = {}
  • l = list() --> l = []

Some nice benefit of this is that literals in Python are quite a bit faster (though only 60 ns - 75 ns):

In [1]: %timeit d = dict()
101 ns ± 0.0829 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

In [2]: %timeit dl = {}
34.1 ns ± 0.378 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

In [3]: %timeit l = list()
101 ns ± 0.541 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

In [4]: %timeit l = []
25.4 ns ± 0.346 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

@googlebot googlebot added the cla: yes PR author has signed CLA label Feb 15, 2019
@afrozenator
Copy link
Contributor

Thanks @lgeiger !

@afrozenator afrozenator merged commit 33b8c5e into tensorflow:master Mar 1, 2019
tensorflow-copybara pushed a commit that referenced this pull request Mar 1, 2019
PiperOrigin-RevId: 236372024
@lgeiger lgeiger deleted the literals branch March 1, 2019 21:55
kpe pushed a commit to kpe/tensor2tensor that referenced this pull request Mar 2, 2019
* d = dict() --> d = {}

* l = list() --> []
kpe pushed a commit to kpe/tensor2tensor that referenced this pull request Mar 2, 2019
PiperOrigin-RevId: 236372024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants