Skip to content

Use dict and set literals instead of calls to dict() and set() #5559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2017
Merged

Use dict and set literals instead of calls to dict() and set() #5559

merged 1 commit into from
Nov 6, 2017

Conversation

jdufresne
Copy link
Contributor

Set literals are available on all supported Python versions. They are idiomatic and always faster:

$ python3 -m timeit '{}'
10000000 loops, best of 3: 0.0357 usec per loop
$ python3 -m timeit 'dict()'
10000000 loops, best of 3: 0.104 usec per loop
$ python3 -m timeit '{1, 2, 3}'
10000000 loops, best of 3: 0.0754 usec per loop
$ python3 -m timeit 'set([1, 2, 3])'
1000000 loops, best of 3: 0.228 usec per loop

Set literals are available on all supported Python versions. They are
idiomatic and always faster:

$ python3 -m timeit '{}'
10000000 loops, best of 3: 0.0357 usec per loop
$ python3 -m timeit 'dict()'
10000000 loops, best of 3: 0.104 usec per loop

$ python3 -m timeit '{1, 2, 3}'
10000000 loops, best of 3: 0.0754 usec per loop
$ python3 -m timeit 'set([1, 2, 3])'
1000000 loops, best of 3: 0.228 usec per loop
@xordoquy
Copy link
Collaborator

xordoquy commented Nov 6, 2017

How much does it impacts a full request ?

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. This looks good.

I think the speed issue is a non-issue really. For me it's more that this syntax will be idiomatic as time passes.

@carltongibson carltongibson added this to the 3.7.2 milestone Nov 6, 2017
@carltongibson carltongibson merged commit 0552810 into encode:master Nov 6, 2017
@jdufresne
Copy link
Contributor Author

How much does it impacts a full request ?

Probably not much in practice. However, literals are always supported, always idiomatic, always readable, and always faster. Most of the time, they're always the preferred choice, even without benchmarks.

@jdufresne jdufresne deleted the literals branch November 9, 2017 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy