Skip to content
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

[New Rule] Use set_default in Python dictionaries #182

Open
Skylion007 opened this issue May 12, 2023 · 0 comments
Open

[New Rule] Use set_default in Python dictionaries #182

Skylion007 opened this issue May 12, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Skylion007
Copy link
Contributor

Explanation

Explain briefly why you think this makes the code simpler.

Example

# Bad
a = {"key": "value"}
if "key" not in a:
    a["key"] = "default_value"

# Good
a = {"key": "value"}
a.set_default("key", "default_value")

Faster, more efficient, removes an if statement.

@Skylion007 Skylion007 added the enhancement New feature or request label May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants