Skip to content

Merge List Extend

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: merge-list-extend

Section titled “Sourcery refactoring id: merge-list-extend”

Create the list with values instead of creating an empty list and extending it with another list

hats_i_own = []
hats_i_own.extend(["panama, baseball_cap, bowler"])
hats_i_own = ["panama", "baseball_cap", "bowler"]

When declaring a list with values it is much clearer to do so on one line rather than declaring an empty list and then extending it with values.