Skip to content

[New Rule] Use set_default in Python dictionaries #182

@Skylion007

Description

@Skylion007

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions